Commit e74f61d6 authored by Lennart Bader's avatar Lennart Bader
Browse files

Added options: Landing Page for startup, VPlan display option, Link behavior for news

parent 67e916eb
package de.mytfg.apps.vplan.activities; package de.mytfg.apps.vplan.activities;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v4.app.FragmentContainer;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
...@@ -8,9 +9,12 @@ import android.support.annotation.Nullable; ...@@ -8,9 +9,12 @@ import android.support.annotation.Nullable;
import android.support.design.widget.NavigationView; import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import java.util.Set;
import de.mytfg.apps.vplan.R; import de.mytfg.apps.vplan.R;
import de.mytfg.apps.vplan.api.MyTFGApi; import de.mytfg.apps.vplan.api.MyTFGApi;
import de.mytfg.apps.vplan.fragments.AboutFragment; import de.mytfg.apps.vplan.fragments.AboutFragment;
...@@ -20,6 +24,7 @@ import de.mytfg.apps.vplan.fragments.PlanFragment; ...@@ -20,6 +24,7 @@ import de.mytfg.apps.vplan.fragments.PlanFragment;
import de.mytfg.apps.vplan.fragments.StartFragment; import de.mytfg.apps.vplan.fragments.StartFragment;
import de.mytfg.apps.vplan.navigation.Navigation; import de.mytfg.apps.vplan.navigation.Navigation;
import de.mytfg.apps.vplan.toolbar.ToolbarManager; import de.mytfg.apps.vplan.toolbar.ToolbarManager;
import de.mytfg.apps.vplan.tools.Settings;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
private NavigationView navigationView; private NavigationView navigationView;
...@@ -92,7 +97,21 @@ public class MainActivity extends AppCompatActivity { ...@@ -92,7 +97,21 @@ public class MainActivity extends AppCompatActivity {
fragment = getSupportFragmentManager().getFragment(savedInstanceState, fragment = getSupportFragmentManager().getFragment(savedInstanceState,
"fragmentInstanceSaved"); "fragmentInstanceSaved");
} else { } else {
fragment = new PlanFragment(); // Read Landing Page from settings
Settings settings = new Settings(context);
int page = settings.getInt("landing_page");
String[] fragmentNames = getResources().getStringArray(R.array.settings_opt_landing_page_fragments);
String fragName = "StartFragment";
if (page >= 0 && page < fragmentNames.length) {
fragName = fragmentNames[page];
}
try {
fragName = "de.mytfg.apps.vplan.fragments." + fragName;
Class c = Class.forName(fragName);
fragment = (Fragment)c.newInstance();
} catch (Exception ex) {
fragment = new StartFragment();
}
} }
} }
navi.navigate(fragment, R.id.fragment_container); navi.navigate(fragment, R.id.fragment_container);
......
...@@ -9,9 +9,12 @@ import android.text.Html; ...@@ -9,9 +9,12 @@ import android.text.Html;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import java.util.Set;
import de.mytfg.apps.vplan.R; import de.mytfg.apps.vplan.R;
import de.mytfg.apps.vplan.objects.TfgNewsEntry; import de.mytfg.apps.vplan.objects.TfgNewsEntry;
import de.mytfg.apps.vplan.objects.VplanEntry; import de.mytfg.apps.vplan.objects.VplanEntry;
import de.mytfg.apps.vplan.tools.Settings;
import static android.view.View.GONE; import static android.view.View.GONE;
...@@ -38,7 +41,8 @@ public class NewsEntryHolder extends RecyclerView.ViewHolder { ...@@ -38,7 +41,8 @@ public class NewsEntryHolder extends RecyclerView.ViewHolder {
date.setText(entry.getDateString()); date.setText(entry.getDateString());
summary.setText(Html.fromHtml(entry.getSummary())); summary.setText(Html.fromHtml(entry.getSummary()));
final String link = entry.getLink(); final String link = entry.getLink();
if (!link.isEmpty()) { Settings settings = new Settings(context);
if (!link.isEmpty() && settings.getBool("news_browser")) {
setOnClickListener(new View.OnClickListener() { setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
......
...@@ -11,6 +11,7 @@ import android.widget.TextView; ...@@ -11,6 +11,7 @@ import android.widget.TextView;
import de.mytfg.apps.vplan.R; import de.mytfg.apps.vplan.R;
import de.mytfg.apps.vplan.objects.VplanEntry; import de.mytfg.apps.vplan.objects.VplanEntry;
import de.mytfg.apps.vplan.tools.Settings;
import static android.view.View.GONE; import static android.view.View.GONE;
...@@ -40,14 +41,18 @@ public class PlanEntryHolder extends RecyclerView.ViewHolder { ...@@ -40,14 +41,18 @@ public class PlanEntryHolder extends RecyclerView.ViewHolder {
} }
public void update(VplanEntry planEntry) { public void update(VplanEntry planEntry) {
Settings settings = new Settings(context);
//titleView.setText(baseObject.getName()); //titleView.setText(baseObject.getName());
lesson.setText(planEntry.getLesson()); lesson.setText(planEntry.getLesson());
plan.setText(planEntry.getPlan()); String planText = settings.getBool("plan_fulltext") ? planEntry.getPlanText() : planEntry.getPlan();
String substText = settings.getBool("plan_fulltext") ? planEntry.getSubstText() : planEntry.getSubstitution();
plan.setText(planText);
if (planEntry.getSubstitution().isEmpty()) { if (planEntry.getSubstitution().isEmpty()) {
substHeader.setVisibility(GONE); substHeader.setVisibility(GONE);
subst.setVisibility(GONE); subst.setVisibility(GONE);
} else { } else {
subst.setText(planEntry.getSubstitution()); subst.setText(substText);
subst.setVisibility(View.VISIBLE); subst.setVisibility(View.VISIBLE);
substHeader.setVisibility(View.VISIBLE); substHeader.setVisibility(View.VISIBLE);
} }
......
...@@ -12,12 +12,17 @@ import android.support.v4.app.Fragment; ...@@ -12,12 +12,17 @@ import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.text.Html; import android.text.Html;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button; import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.Spinner;
import android.widget.Switch;
import android.widget.TextView; import android.widget.TextView;
import org.json.JSONArray; import org.json.JSONArray;
...@@ -35,6 +40,7 @@ import de.mytfg.apps.vplan.api.ApiCallback; ...@@ -35,6 +40,7 @@ import de.mytfg.apps.vplan.api.ApiCallback;
import de.mytfg.apps.vplan.api.ApiParams; import de.mytfg.apps.vplan.api.ApiParams;
import de.mytfg.apps.vplan.api.MyTFGApi; import de.mytfg.apps.vplan.api.MyTFGApi;
import de.mytfg.apps.vplan.objects.User; import de.mytfg.apps.vplan.objects.User;
import de.mytfg.apps.vplan.tools.Settings;
public class SettingsFragment extends Fragment { public class SettingsFragment extends Fragment {
private View view; private View view;
...@@ -95,6 +101,8 @@ public class SettingsFragment extends Fragment { ...@@ -95,6 +101,8 @@ public class SettingsFragment extends Fragment {
} }
}); });
updateSettings();
updateAdditionalClasses(); updateAdditionalClasses();
return view; return view;
...@@ -267,4 +275,40 @@ public class SettingsFragment extends Fragment { ...@@ -267,4 +275,40 @@ public class SettingsFragment extends Fragment {
} }
}); });
} }
private void updateSettings() {
Switch fulltext = (Switch) view.findViewById(R.id.switch_fulltext);
Switch newsbrowser = (Switch) view.findViewById(R.id.switch_news_browser);
Spinner landing = (Spinner) view.findViewById(R.id.spinner_landing);
final Settings settings = new Settings(context);
fulltext.setChecked(settings.getBool("plan_fulltext"));
fulltext.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
settings.save("plan_fulltext", b);
}
});
newsbrowser.setChecked(settings.getBool("news_browser"));
newsbrowser.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
settings.save("news_browser", b);
}
});
landing.setSelection(settings.getInt("landing_page"));
landing.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
settings.save("landing_page", i);
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
}
} }
package de.mytfg.apps.vplan.tools;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import java.net.ContentHandler;
import java.util.Set;
/**
* Manages storage of settings for easy access
*/
public class Settings {
private Context context;
private SharedPreferences preferences;
public Settings(Context context) {
this.context = context;
preferences = context.getSharedPreferences("settings", Context.MODE_PRIVATE);
}
public void save(String option, String value) {
preferences.edit()
.putString(option, value)
.apply();
}
public void save(String option, boolean value) {
preferences.edit()
.putBoolean(option, value)
.apply();
}
public void save(String option, int value) {
preferences.edit()
.putInt(option, value)
.apply();
Log.d("SAVE", option + ": " + value);
}
public boolean getBool(String option) {
return preferences.getBoolean(option, false);
}
public String getString(String option) {
return preferences.getString(option, "");
}
public int getInt(String option) {
return preferences.getInt(option, 0);
}
}
<android.support.v4.widget.NestedScrollView <android.support.v4.widget.NestedScrollView xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:fitsSystemWindows="true" android:fitsSystemWindows="true"
...@@ -92,6 +92,64 @@ ...@@ -92,6 +92,64 @@
</LinearLayout> </LinearLayout>
</android.support.v7.widget.CardView> </android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/cardview_spacing"
android:layout_marginBottom="@dimen/defaultPadding">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/cardview_spacing"
android:background="@color/colorPrimaryLight">
<TextView
android:textSize="@dimen/textTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/settings_general_title"
android:id="@+id/settings_general"/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
<Switch
android:text="@string/settings_opt_fulltext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:id="@+id/switch_fulltext" />
<Switch
android:text="@string/settings_opt_newslink"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:id="@+id/switch_news_browser" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimaryText"
android:textSize="@dimen/textSmallTitle"
android:text="@string/settings_opt_landing_page" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/settings_opt_landing_page_entries"
android:id="@+id/spinner_landing" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout> </LinearLayout>
</android.support.v4.widget.NestedScrollView> </android.support.v4.widget.NestedScrollView>
\ No newline at end of file
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
android:theme="@style/AppTheme" android:theme="@style/AppTheme"
android:background="@color/colorPrimaryDark" android:background="@color/colorPrimaryDark"
app:tabTextAppearance="@style/AppTheme.TabTextAppearance" app:tabTextAppearance="@style/AppTheme.TabTextAppearance"
app:tabTextColor="@color/colorSecondaryText" app:tabTextColor="@color/colorIconsDark"
app:tabSelectedTextColor="@color/colorIcons" app:tabSelectedTextColor="@color/colorIcons"
app:tabIndicatorColor="@color/colorAccent" app:tabIndicatorColor="@color/colorAccent"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
......
...@@ -101,6 +101,12 @@ ...@@ -101,6 +101,12 @@
<string name="account_accept">Speichern</string> <string name="account_accept">Speichern</string>
<string name="account_discard">Verwerfen</string> <string name="account_discard">Verwerfen</string>
<!-- SETTING -->
<string name="settings_general_title">Einstellungen</string>
<string name="settings_opt_newslink">News im Browser öffnen</string>
<string name="settings_opt_fulltext">VPlan als Volltext anzeigen</string>
<string name="settings_opt_landing_page">Standardansicht</string>
<!-- USER --> <!-- USER -->
<string name="user_rights_norights">Nicht eingeloggt</string> <string name="user_rights_norights">Nicht eingeloggt</string>
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
<item name="android:windowTranslucentStatus">true</item> <item name="android:windowTranslucentStatus">true</item>
<item name="android:colorPrimary">@color/colorPrimary</item> <item name="android:colorPrimary">@color/colorPrimary</item>
<item name="android:colorPrimaryDark">@color/colorPrimaryDark</item> <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:textColorTertiary">@color/colorSecondaryText</item>
<item name="android:textColorSecondary">@color/colorSecondaryText</item>
<item name="android:colorAccent">@color/colorAccent</item> <item name="android:colorAccent">@color/colorAccent</item>
<item name="android:colorControlNormal">@color/colorPrimaryDark</item> <item name="android:colorControlNormal">@color/colorPrimaryDark</item>
<item name="android:colorControlActivated">@color/colorAccent</item> <item name="android:colorControlActivated">@color/colorAccent</item>
...@@ -16,4 +18,9 @@ ...@@ -16,4 +18,9 @@
<item name="android:indeterminateTint">@color/colorAccent</item> <item name="android:indeterminateTint">@color/colorAccent</item>
<item name="android:progressBackgroundTint">@color/colorAccent</item> <item name="android:progressBackgroundTint">@color/colorAccent</item>
</style> </style>
<style name="AppTheme.Switch" parent="Base.Widget.AppCompat.CompoundButton.Switch">
<item name="android:layout_marginBottom">10dp</item>
<item name="android:colorControlActivated">@color/colorAccent</item>
</style>
</resources> </resources>
\ No newline at end of file
...@@ -5,8 +5,9 @@ ...@@ -5,8 +5,9 @@
<color name="colorPrimaryLight">#C5CAE9</color> <color name="colorPrimaryLight">#C5CAE9</color>
<color name="colorSecondaryLight">#DFE2F4</color> <color name="colorSecondaryLight">#DFE2F4</color>
<color name="colorIcons">#FFFFFF</color> <color name="colorIcons">#FFFFFF</color>
<color name="colorPrimaryText">#212121</color> <color name="colorIconsDark">#dddddd</color>
<color name="colorSecondaryText">#DDDDDD</color> <color name="colorPrimaryText">#000000</color>
<color name="colorSecondaryText">#333333</color>
<color name="colorDivider">#B6B6B6</color> <color name="colorDivider">#B6B6B6</color>
<color name="colorAccent">#FF7400</color> <color name="colorAccent">#FF7400</color>
......
...@@ -100,6 +100,22 @@ ...@@ -100,6 +100,22 @@
<string name="account_accept">OK</string> <string name="account_accept">OK</string>
<string name="account_discard">Discard</string> <string name="account_discard">Discard</string>
<!-- SETTING -->
<string name="settings_general_title">Settings</string>
<string name="settings_opt_newslink">Open News in Browser</string>
<string name="settings_opt_fulltext">Show Plan as Fulltext</string>
<string name="settings_opt_landing_page">Default Page</string>
<string-array name="settings_opt_landing_page_entries">
<item>@string/menutitle_home</item>
<item>@string/menutitle_plan</item>
<item>@string/menutitle_about</item>
</string-array>
<string-array name="settings_opt_landing_page_fragments">
<item>StartFragment</item>
<item>PlanFragment</item>
<item>AboutFragment</item>
</string-array>
<!-- USER --> <!-- USER -->
<string name="user_rights_norights">Not logged in</string> <string name="user_rights_norights">Not logged in</string>
<string name="user_rights_pupil">Pupil</string> <string name="user_rights_pupil">Pupil</string>
......
...@@ -54,5 +54,4 @@ ...@@ -54,5 +54,4 @@
<item name="android:textColor">@color/colorIcons</item> <item name="android:textColor">@color/colorIcons</item>
<item name="android:textAllCaps">false</item> <item name="android:textAllCaps">false</item>
</style> </style>
</resources> </resources>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment