Browse Source

Add option for main screen tabs style

pull/71/merge
Ezerous 4 years ago
parent
commit
97f87016b0
  1. 26
      app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java
  2. 1
      app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsActivity.java
  3. 4
      app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java
  4. 7
      app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java
  5. 1
      app/src/main/res/layout/activity_main.xml
  6. 4
      app/src/main/res/layout/fragment_forum.xml
  7. 4
      app/src/main/res/layout/fragment_recent.xml
  8. 4
      app/src/main/res/layout/fragment_unread.xml
  9. 1
      app/src/main/res/values/dimens.xml
  10. 3
      app/src/main/res/values/strings.xml
  11. 6
      app/src/main/res/xml-v26/app_preferences_guest.xml
  12. 6
      app/src/main/res/xml-v26/app_preferences_user.xml
  13. 6
      app/src/main/res/xml/app_preferences_guest.xml
  14. 6
      app/src/main/res/xml/app_preferences_user.xml

26
app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java

@ -55,6 +55,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
private SectionsPagerAdapter sectionsPagerAdapter; private SectionsPagerAdapter sectionsPagerAdapter;
private ViewPager viewPager; private ViewPager viewPager;
private TabLayout tabLayout; private TabLayout tabLayout;
private boolean displayCompactTabs;
//Fix for vector drawables on android <21 //Fix for vector drawables on android <21
static { static {
@ -82,9 +83,13 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
return; //Avoid executing the code below return; //Avoid executing the code below
} }
toolbar = findViewById(R.id.toolbar); displayCompactTabs = BaseApplication.getInstance().isDisplayCompactTabsEnabled();
toolbar.setTitle("");
setSupportActionBar(toolbar); if(displayCompactTabs) {
toolbar = findViewById(R.id.toolbar);
toolbar.setTitle("");
setSupportActionBar(toolbar);
}
//Initialize drawer //Initialize drawer
createDrawer(); createDrawer();
@ -108,8 +113,8 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
if ((preferredTab != 3 && preferredTab != 4) || sessionManager.isLoggedIn()) if ((preferredTab != 3 && preferredTab != 4) || sessionManager.isLoggedIn())
tabLayout.getTabAt(preferredTab).select(); tabLayout.getTabAt(preferredTab).select();
for (int i = 0; i < tabLayout.getTabCount(); i++) if(!displayCompactTabs)
updateTabIcon(i); updateTabIcons();
setMainActivity(this); setMainActivity(this);
} }
@ -189,7 +194,8 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
fragmentList.add(fragment); fragmentList.add(fragment);
fragmentTitleList.add(title); fragmentTitleList.add(title);
notifyDataSetChanged(); notifyDataSetChanged();
updateTabIcon(fragmentList.size() - 1); if(!displayCompactTabs)
updateTabIcon(fragmentList.size() - 1);
} }
void removeFragment(int position) { void removeFragment(int position) {
@ -234,6 +240,10 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
tabLayout.getTabAt(2).setIcon(getResources().getDrawable(R.drawable.ic_fiber_new_white_24dp)); tabLayout.getTabAt(2).setIcon(getResources().getDrawable(R.drawable.ic_fiber_new_white_24dp));
} }
private void updateTabIcons (){
for (int i = 0; i < tabLayout.getTabCount(); i++)
updateTabIcon(i);
}
public void updateTabs() { public void updateTabs() {
if (!sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 3) if (!sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 3)
@ -241,8 +251,8 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
else if (sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 2) else if (sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 2)
sectionsPagerAdapter.addFragment(UnreadFragment.newInstance(3), "UNREAD"); sectionsPagerAdapter.addFragment(UnreadFragment.newInstance(3), "UNREAD");
for (int i = 0; i < tabLayout.getTabCount(); i++) if(!displayCompactTabs)
updateTabIcon(i); updateTabIcons();
} }
//-------------------------------FragmentPagerAdapter END------------------------------------------- //-------------------------------FragmentPagerAdapter END-------------------------------------------

1
app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsActivity.java

@ -9,6 +9,7 @@ import gr.thmmy.mthmmy.base.BaseActivity;
public class SettingsActivity extends BaseActivity { public class SettingsActivity extends BaseActivity {
public static final String DEFAULT_HOME_TAB = "pref_app_main_default_tab_key"; public static final String DEFAULT_HOME_TAB = "pref_app_main_default_tab_key";
public static final String DISPLAY_COMPACT_TABS = "pref_app_display_compact_tabs_key";
public static final String DISPLAY_RELATIVE_TIME = "pref_app_display_relative_time_key"; public static final String DISPLAY_RELATIVE_TIME = "pref_app_display_relative_time_key";
public static final String NOTIFICATION_LED_KEY = "pref_notification_led_enable_key"; public static final String NOTIFICATION_LED_KEY = "pref_notification_led_enable_key";
public static final String NOTIFICATION_VIBRATION_KEY = "pref_notification_vibration_enable_key"; public static final String NOTIFICATION_VIBRATION_KEY = "pref_notification_vibration_enable_key";

4
app/src/main/java/gr/thmmy/mthmmy/activities/settings/SettingsFragment.java

@ -224,6 +224,10 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
&& BaseApplication.getInstance().isDisplayRelativeTimeEnabled() != sharedPreferences.getBoolean(key, false)) { && BaseApplication.getInstance().isDisplayRelativeTimeEnabled() != sharedPreferences.getBoolean(key, false)) {
displayRestartAppToTakeEffectToast(); displayRestartAppToTakeEffectToast();
} }
else if (key.equals(getString(R.string.pref_app_display_compact_tabs_key))
&& BaseApplication.getInstance().isDisplayCompactTabsEnabled() != sharedPreferences.getBoolean(key, false)) {
displayRestartAppToTakeEffectToast();
}
} }
private void displayRestartAppToTakeEffectToast() { private void displayRestartAppToTakeEffectToast() {

7
app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java

@ -47,6 +47,7 @@ import okhttp3.Request;
import timber.log.Timber; import timber.log.Timber;
import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.DISPLAY_RELATIVE_TIME; import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.DISPLAY_RELATIVE_TIME;
import static gr.thmmy.mthmmy.activities.settings.SettingsActivity.DISPLAY_COMPACT_TABS;
// TODO: Replace MultiDexApplication with Application after KitKat support is dropped // TODO: Replace MultiDexApplication with Application after KitKat support is dropped
public class BaseApplication extends MultiDexApplication { public class BaseApplication extends MultiDexApplication {
@ -63,6 +64,7 @@ public class BaseApplication extends MultiDexApplication {
private SessionManager sessionManager; private SessionManager sessionManager;
private boolean displayRelativeTime; private boolean displayRelativeTime;
private boolean displayCompactTabs;
//Display Metrics //Display Metrics
private static float widthDp; private static float widthDp;
@ -105,6 +107,7 @@ public class BaseApplication extends MultiDexApplication {
setDisplayMetrics(); setDisplayMetrics();
displayRelativeTime = settingsSharedPrefs.getBoolean(DISPLAY_RELATIVE_TIME, true); displayRelativeTime = settingsSharedPrefs.getBoolean(DISPLAY_RELATIVE_TIME, true);
displayCompactTabs = settingsSharedPrefs.getBoolean(DISPLAY_COMPACT_TABS, true);
} }
private void initFirebase(SharedPreferences settingsSharedPrefs) { private void initFirebase(SharedPreferences settingsSharedPrefs) {
@ -233,6 +236,10 @@ public class BaseApplication extends MultiDexApplication {
return displayRelativeTime; return displayRelativeTime;
} }
public boolean isDisplayCompactTabsEnabled() {
return displayCompactTabs;
}
//-------------------- Firebase -------------------- //-------------------- Firebase --------------------
public void logFirebaseAnalyticsEvent(String event, Bundle params) { public void logFirebaseAnalyticsEvent(String event, Bundle params) {

1
app/src/main/res/layout/activity_main.xml

@ -33,6 +33,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_weight="1.0" android:layout_weight="1.0"
android:paddingBottom="2dp"
app:tabMaxWidth="0dp" app:tabMaxWidth="0dp"
app:tabGravity="fill" app:tabGravity="fill"
app:tabMode="fixed" app:tabMode="fixed"

4
app/src/main/res/layout/fragment_forum.xml

@ -17,7 +17,6 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/background" android:background="@color/background"
android:paddingBottom="4dp" android:paddingBottom="4dp"
android:paddingTop="4dp"
app:layoutManager="LinearLayoutManager" app:layoutManager="LinearLayoutManager"
tools:context=".activities.main.forum.ForumFragment" /> tools:context=".activities.main.forum.ForumFragment" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout> </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
@ -26,11 +25,12 @@
android:id="@+id/progressBar" android:id="@+id/progressBar"
style="@style/Widget.MaterialProgressBar.ProgressBar.Horizontal.NoPadding" style="@style/Widget.MaterialProgressBar.ProgressBar.Horizontal.NoPadding"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/progress_bar_height" android:layout_height="@dimen/progress_bar_unpadded_height"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:indeterminate="true" android:indeterminate="true"
android:visibility="invisible" android:visibility="invisible"
app:mpb_indeterminateTint="@color/accent" app:mpb_indeterminateTint="@color/accent"
app:mpb_useIntrinsicPadding = "false"
app:mpb_progressStyle="horizontal" /> app:mpb_progressStyle="horizontal" />
</RelativeLayout> </RelativeLayout>

4
app/src/main/res/layout/fragment_recent.xml

@ -17,7 +17,6 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/background" android:background="@color/background"
android:paddingBottom="4dp" android:paddingBottom="4dp"
android:paddingTop="4dp"
app:layoutManager="LinearLayoutManager" app:layoutManager="LinearLayoutManager"
tools:context=".activities.main.recent.RecentFragment" tools:context=".activities.main.recent.RecentFragment"
tools:listitem="@layout/fragment_recent_row" /> tools:listitem="@layout/fragment_recent_row" />
@ -27,10 +26,11 @@
android:id="@+id/progressBar" android:id="@+id/progressBar"
style="@style/Widget.MaterialProgressBar.ProgressBar.Horizontal.NoPadding" style="@style/Widget.MaterialProgressBar.ProgressBar.Horizontal.NoPadding"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/progress_bar_height" android:layout_height="@dimen/progress_bar_unpadded_height"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:indeterminate="true" android:indeterminate="true"
android:visibility="invisible" android:visibility="invisible"
app:mpb_indeterminateTint="@color/accent" app:mpb_indeterminateTint="@color/accent"
app:mpb_useIntrinsicPadding = "false"
app:mpb_progressStyle="horizontal" /> app:mpb_progressStyle="horizontal" />
</RelativeLayout> </RelativeLayout>

4
app/src/main/res/layout/fragment_unread.xml

@ -23,7 +23,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/background" android:background="@color/background"
android:paddingTop="4dp"
android:paddingBottom="4dp" android:paddingBottom="4dp"
app:layoutManager="LinearLayoutManager" app:layoutManager="LinearLayoutManager"
tools:context=".activities.main.unread.UnreadFragment" tools:context=".activities.main.unread.UnreadFragment"
@ -47,11 +46,12 @@
android:id="@+id/progressBar" android:id="@+id/progressBar"
style="@style/Widget.MaterialProgressBar.ProgressBar.Horizontal.NoPadding" style="@style/Widget.MaterialProgressBar.ProgressBar.Horizontal.NoPadding"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/progress_bar_height" android:layout_height="@dimen/progress_bar_unpadded_height"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:indeterminate="true" android:indeterminate="true"
android:visibility="invisible" android:visibility="invisible"
app:mpb_indeterminateTint="@color/accent" app:mpb_indeterminateTint="@color/accent"
app:mpb_useIntrinsicPadding = "false"
app:mpb_progressStyle="horizontal" /> app:mpb_progressStyle="horizontal" />
<com.google.android.material.floatingactionbutton.FloatingActionButton <com.google.android.material.floatingactionbutton.FloatingActionButton

1
app/src/main/res/values/dimens.xml

@ -7,6 +7,7 @@
<dimen name="post_image_button">36dp</dimen> <dimen name="post_image_button">36dp</dimen>
<dimen name="fab_margins">16dp</dimen> <dimen name="fab_margins">16dp</dimen>
<dimen name="progress_bar_height">10dp</dimen> <dimen name="progress_bar_height">10dp</dimen>
<dimen name="progress_bar_unpadded_height">3dp</dimen>
<dimen name="medium_text">16sp</dimen> <dimen name="medium_text">16sp</dimen>
<dimen name="big_text">24sp</dimen> <dimen name="big_text">24sp</dimen>
<dimen name="editor_format_button_size">24dp</dimen> <dimen name="editor_format_button_size">24dp</dimen>

3
app/src/main/res/values/strings.xml

@ -175,6 +175,9 @@
<string name="pref_app_display_relative_time_key">pref_app_display_relative_time_key</string> <string name="pref_app_display_relative_time_key">pref_app_display_relative_time_key</string>
<string name="pref_title_display_relative_time">Display relative time</string> <string name="pref_title_display_relative_time">Display relative time</string>
<string name="pref_summary_display_relative_time">Considering that you haven\'t set some weird custom time format</string> <string name="pref_summary_display_relative_time">Considering that you haven\'t set some weird custom time format</string>
<string name="pref_app_display_compact_tabs_key">pref_app_display_compact_tabs_key</string>
<string name="pref_title_display_compact_tabs">Display compact tabs</string>
<string name="pref_summary_display_compact_tabs">Home screen tabs will occupy less space</string>
<string name="pref_category_notifications">Notifications</string> <string name="pref_category_notifications">Notifications</string>
<string name="pref_notification_vibration_enable_key">pref_notification_vibration_enable_key</string> <string name="pref_notification_vibration_enable_key">pref_notification_vibration_enable_key</string>

6
app/src/main/res/xml-v26/app_preferences_guest.xml

@ -20,6 +20,12 @@
android:title="@string/pref_title_display_relative_time" android:title="@string/pref_title_display_relative_time"
android:summary="@string/pref_summary_display_relative_time" android:summary="@string/pref_summary_display_relative_time"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="@string/pref_app_display_compact_tabs_key"
android:title="@string/pref_title_display_compact_tabs"
android:summary="@string/pref_summary_display_compact_tabs"
app:iconSpaceReserved="false" />
</androidx.preference.PreferenceCategory> </androidx.preference.PreferenceCategory>
<androidx.preference.PreferenceCategory <androidx.preference.PreferenceCategory

6
app/src/main/res/xml-v26/app_preferences_user.xml

@ -20,6 +20,12 @@
android:title="@string/pref_title_display_relative_time" android:title="@string/pref_title_display_relative_time"
android:summary="@string/pref_summary_display_relative_time" android:summary="@string/pref_summary_display_relative_time"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="@string/pref_app_display_compact_tabs_key"
android:title="@string/pref_title_display_compact_tabs"
android:summary="@string/pref_summary_display_compact_tabs"
app:iconSpaceReserved="false" />
</androidx.preference.PreferenceCategory> </androidx.preference.PreferenceCategory>
<androidx.preference.PreferenceCategory <androidx.preference.PreferenceCategory

6
app/src/main/res/xml/app_preferences_guest.xml

@ -20,6 +20,12 @@
android:title="@string/pref_title_display_relative_time" android:title="@string/pref_title_display_relative_time"
android:summary="@string/pref_summary_display_relative_time" android:summary="@string/pref_summary_display_relative_time"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="@string/pref_app_display_compact_tabs_key"
android:title="@string/pref_title_display_compact_tabs"
android:summary="@string/pref_summary_display_compact_tabs"
app:iconSpaceReserved="false" />
</androidx.preference.PreferenceCategory> </androidx.preference.PreferenceCategory>
<androidx.preference.PreferenceCategory <androidx.preference.PreferenceCategory

6
app/src/main/res/xml/app_preferences_user.xml

@ -20,6 +20,12 @@
android:title="@string/pref_title_display_relative_time" android:title="@string/pref_title_display_relative_time"
android:summary="@string/pref_summary_display_relative_time" android:summary="@string/pref_summary_display_relative_time"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="@string/pref_app_display_compact_tabs_key"
android:title="@string/pref_title_display_compact_tabs"
android:summary="@string/pref_summary_display_compact_tabs"
app:iconSpaceReserved="false" />
</androidx.preference.PreferenceCategory> </androidx.preference.PreferenceCategory>
<androidx.preference.PreferenceCategory <androidx.preference.PreferenceCategory

Loading…
Cancel
Save