Browse Source

Optional style for main screen tabs

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

10
app/build.gradle

@ -15,8 +15,8 @@ android {
applicationId "gr.thmmy.mthmmy"
minSdkVersion 19
targetSdkVersion 29
versionCode 28
versionName "1.8.5"
versionCode 29
versionName "1.9.0"
archivesBaseName = "mTHMMY-v$versionName"
buildConfigField "String", "CURRENT_BRANCH", "\"" + getCurrentBranch() + "\""
buildConfigField "String", "COMMIT_HASH", "\"" + getCommitHash() + "\""
@ -83,13 +83,13 @@ dependencies {
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.exifinterface:exifinterface:1.2.0'
implementation 'androidx.multidex:multidex:2.0.1' //TODO: Remove when minSdkVersion >= 21
implementation 'com.google.android.material:material:1.1.0'
implementation 'com.google.firebase:firebase-analytics:17.4.4'
implementation 'com.google.firebase:firebase-crashlytics:17.1.1'
implementation 'com.google.firebase:firebase-messaging:20.2.4'
implementation 'com.google.firebase:firebase-crashlytics:17.3.0'
implementation 'com.google.firebase:firebase-messaging:21.0.0'
implementation 'com.snatik:storage:2.1.0'
implementation('com.squareup.okhttp3:okhttp:3.12.12') {
//TODO: Warning: OkHttp has dropped support for Android 19 since OkHttp 3.13!

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

@ -5,6 +5,8 @@ import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatDelegate;
@ -55,6 +57,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
private SectionsPagerAdapter sectionsPagerAdapter;
private ViewPager viewPager;
private TabLayout tabLayout;
private boolean displayCompactTabs;
//Fix for vector drawables on android <21
static {
@ -82,9 +85,15 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
return; //Avoid executing the code below
}
toolbar = findViewById(R.id.toolbar);
toolbar.setTitle("");
setSupportActionBar(toolbar);
displayCompactTabs = BaseApplication.getInstance().isDisplayCompactTabsEnabled();
if (displayCompactTabs) {
toolbar = findViewById(R.id.toolbar);
ViewGroup.LayoutParams currentParams = toolbar.getLayoutParams();
toolbar.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, currentParams.height));
toolbar.setTitle("");
setSupportActionBar(toolbar);
}
//Initialize drawer
createDrawer();
@ -108,8 +117,8 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
if ((preferredTab != 3 && preferredTab != 4) || sessionManager.isLoggedIn())
tabLayout.getTabAt(preferredTab).select();
for (int i = 0; i < tabLayout.getTabCount(); i++)
updateTabIcon(i);
if (!displayCompactTabs)
updateTabIcons();
setMainActivity(this);
}
@ -189,7 +198,8 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
fragmentList.add(fragment);
fragmentTitleList.add(title);
notifyDataSetChanged();
updateTabIcon(fragmentList.size() - 1);
if (!displayCompactTabs)
updateTabIcon(fragmentList.size() - 1);
}
void removeFragment(int position) {
@ -234,6 +244,10 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
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() {
if (!sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 3)
@ -241,8 +255,8 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
else if (sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 2)
sectionsPagerAdapter.addFragment(UnreadFragment.newInstance(3), "UNREAD");
for (int i = 0; i < tabLayout.getTabCount(); i++)
updateTabIcon(i);
if (!displayCompactTabs)
updateTabIcons();
}
//-------------------------------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 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 NOTIFICATION_LED_KEY = "pref_notification_led_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)) {
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() {

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

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

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

@ -22,7 +22,7 @@
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:contentInsetStartWithNavigation="0dp"
@ -33,6 +33,7 @@
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1.0"
android:paddingBottom="2dp"
app:tabMaxWidth="0dp"
app:tabGravity="fill"
app:tabMode="fixed"

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

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

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

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

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

@ -23,7 +23,6 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background"
android:paddingTop="4dp"
android:paddingBottom="4dp"
app:layoutManager="LinearLayoutManager"
tools:context=".activities.main.unread.UnreadFragment"
@ -47,11 +46,12 @@
android:id="@+id/progressBar"
style="@style/Widget.MaterialProgressBar.ProgressBar.Horizontal.NoPadding"
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:indeterminate="true"
android:visibility="invisible"
app:mpb_indeterminateTint="@color/accent"
app:mpb_useIntrinsicPadding="false"
app:mpb_progressStyle="horizontal" />
<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="fab_margins">16dp</dimen>
<dimen name="progress_bar_height">10dp</dimen>
<dimen name="progress_bar_unpadded_height">3dp</dimen>
<dimen name="medium_text">16sp</dimen>
<dimen name="big_text">24sp</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_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_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_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:summary="@string/pref_summary_display_relative_time"
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

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

@ -20,6 +20,12 @@
android:title="@string/pref_title_display_relative_time"
android:summary="@string/pref_summary_display_relative_time"
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

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

@ -20,6 +20,12 @@
android:title="@string/pref_title_display_relative_time"
android:summary="@string/pref_summary_display_relative_time"
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

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

@ -20,6 +20,12 @@
android:title="@string/pref_title_display_relative_time"
android:summary="@string/pref_summary_display_relative_time"
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

4
build.gradle

@ -9,8 +9,8 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
classpath 'com.google.gms:google-services:4.3.3'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.2.0'
classpath 'com.google.gms:google-services:4.3.4'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.4.1'
classpath 'org.ajoberstar.grgit:grgit-core:3.1.1' // Also change in app/gradle/grgit.gradle
classpath "com.github.ben-manes:gradle-versions-plugin:0.21.0"
}

4
gradle/wrapper/gradle-wrapper.properties

@ -1,6 +1,6 @@
#Wed Nov 11 12:38:13 EET 2020
#Thu Dec 03 14:56:57 EET 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip

Loading…
Cancel
Save