Move about and rate to settings screen (#714)

Move about and rate to settings screen

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/714
This commit is contained in:
M M Arif 2020-09-27 09:36:57 +02:00
parent 8612258174
commit bf19e52799
6 changed files with 96 additions and 43 deletions

View File

@ -1,13 +1,11 @@
package org.mian.gitnex.activities; package org.mian.gitnex.activities;
import android.app.Activity; import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
@ -33,7 +31,6 @@ import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.clients.RetrofitClient; import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.database.api.UserAccountsApi; import org.mian.gitnex.database.api.UserAccountsApi;
import org.mian.gitnex.database.models.UserAccount; import org.mian.gitnex.database.models.UserAccount;
import org.mian.gitnex.fragments.AboutFragment;
import org.mian.gitnex.fragments.AdministrationFragment; import org.mian.gitnex.fragments.AdministrationFragment;
import org.mian.gitnex.fragments.BottomSheetDraftsFragment; import org.mian.gitnex.fragments.BottomSheetDraftsFragment;
import org.mian.gitnex.fragments.DraftsFragment; import org.mian.gitnex.fragments.DraftsFragment;
@ -188,9 +185,6 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
else if(fragmentById instanceof ProfileFragment) { else if(fragmentById instanceof ProfileFragment) {
toolbarTitle.setText(getResources().getString(R.string.pageTitleProfile)); toolbarTitle.setText(getResources().getString(R.string.pageTitleProfile));
} }
else if(fragmentById instanceof AboutFragment) {
toolbarTitle.setText(getResources().getString(R.string.pageTitleAbout));
}
else if(fragmentById instanceof DraftsFragment) { else if(fragmentById instanceof DraftsFragment) {
toolbarTitle.setText(getResources().getString(R.string.titleDrafts)); toolbarTitle.setText(getResources().getString(R.string.titleDrafts));
} }
@ -455,6 +449,11 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
} }
} }
public void setActionBarTitle(String title) {
toolbarTitle.setText(title);
}
@Override @Override
public void onButtonClicked(String text) { public void onButtonClicked(String text) {
@ -544,15 +543,6 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
break; break;
case R.id.nav_about:
toolbarTitle.setText(getResources().getString(R.string.pageTitleAbout));
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new AboutFragment()).commit();
break;
case R.id.nav_rate_app:
rateThisApp();
break;
case R.id.nav_starred_repos: case R.id.nav_starred_repos:
toolbarTitle.setText(getResources().getString(R.string.pageTitleStarredRepos)); toolbarTitle.setText(getResources().getString(R.string.pageTitleStarredRepos));
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new StarredRepositoriesFragment()).commit(); getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new StarredRepositoriesFragment()).commit();
@ -584,16 +574,6 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
return true; return true;
} }
public void rateThisApp() {
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getPackageName())));
}
catch(ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + getPackageName())));
}
}
public static void logout(Activity activity, Context ctx) { public static void logout(Activity activity, Context ctx) {
TinyDB tinyDb = new TinyDB(ctx.getApplicationContext()); TinyDB tinyDb = new TinyDB(ctx.getApplicationContext());

View File

@ -9,6 +9,7 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import org.mian.gitnex.R; import org.mian.gitnex.R;
import org.mian.gitnex.activities.MainActivity;
import org.mian.gitnex.databinding.FragmentAboutBinding; import org.mian.gitnex.databinding.FragmentAboutBinding;
import org.mian.gitnex.helpers.AppUtil; import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.TinyDB; import org.mian.gitnex.helpers.TinyDB;
@ -29,6 +30,8 @@ public class AboutFragment extends Fragment {
viewBinding.userServerVersion.setText(tinyDb.getString("giteaVersion")); viewBinding.userServerVersion.setText(tinyDb.getString("giteaVersion"));
viewBinding.appBuild.setText(String.valueOf(AppUtil.getAppBuildNo(requireContext()))); viewBinding.appBuild.setText(String.valueOf(AppUtil.getAppBuildNo(requireContext())));
((MainActivity) requireActivity()).setActionBarTitle(getResources().getString(R.string.pageTitleAbout));
viewBinding.donationLinkLiberapay.setOnClickListener(v1 -> { viewBinding.donationLinkLiberapay.setOnClickListener(v1 -> {
Intent intent = new Intent(); Intent intent = new Intent();

View File

@ -1,6 +1,8 @@
package org.mian.gitnex.fragments; package org.mian.gitnex.fragments;
import android.content.ActivityNotFoundException;
import android.content.Intent; import android.content.Intent;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -17,7 +19,6 @@ import org.mian.gitnex.activities.SettingsReportsActivity;
import org.mian.gitnex.activities.SettingsSecurityActivity; import org.mian.gitnex.activities.SettingsSecurityActivity;
import org.mian.gitnex.activities.SettingsTranslationActivity; import org.mian.gitnex.activities.SettingsTranslationActivity;
import org.mian.gitnex.helpers.TinyDB; import org.mian.gitnex.helpers.TinyDB;
import java.util.Objects;
/** /**
* Author M M Arif * Author M M Arif
@ -37,6 +38,8 @@ public class SettingsFragment extends Fragment {
LinearLayout securityFrame = v.findViewById(R.id.securityFrame); LinearLayout securityFrame = v.findViewById(R.id.securityFrame);
LinearLayout languagesFrame = v.findViewById(R.id.languagesFrame); LinearLayout languagesFrame = v.findViewById(R.id.languagesFrame);
LinearLayout reportsFrame = v.findViewById(R.id.reportsFrame); LinearLayout reportsFrame = v.findViewById(R.id.reportsFrame);
LinearLayout rateAppFrame = v.findViewById(R.id.rateAppFrame);
LinearLayout aboutAppFrame = v.findViewById(R.id.aboutAppFrame);
appearanceFrame.setOnClickListener(v1 -> startActivity(new Intent(getContext(), SettingsAppearanceActivity.class))); appearanceFrame.setOnClickListener(v1 -> startActivity(new Intent(getContext(), SettingsAppearanceActivity.class)));
@ -50,10 +53,24 @@ public class SettingsFragment extends Fragment {
reportsFrame.setOnClickListener(v1 -> startActivity(new Intent(getContext(), SettingsReportsActivity.class))); reportsFrame.setOnClickListener(v1 -> startActivity(new Intent(getContext(), SettingsReportsActivity.class)));
rateAppFrame.setOnClickListener(aboutApp -> rateThisApp());
aboutAppFrame.setOnClickListener(aboutApp -> requireActivity().getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new AboutFragment()).commit());
return v; return v;
} }
public void rateThisApp() {
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + requireActivity().getPackageName())));
}
catch(ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + requireActivity().getPackageName())));
}
}
@Override @Override
public void onResume() { public void onResume() {
@ -62,8 +79,8 @@ public class SettingsFragment extends Fragment {
TinyDB tinyDb = new TinyDB(getContext()); TinyDB tinyDb = new TinyDB(getContext());
if(tinyDb.getBoolean("refreshParent")) { if(tinyDb.getBoolean("refreshParent")) {
Objects.requireNonNull(getActivity()).recreate(); requireActivity().recreate();
getActivity().overridePendingTransition(0, 0); requireActivity().overridePendingTransition(0, 0);
tinyDb.putBoolean("refreshParent", false); tinyDb.putBoolean("refreshParent", false);
} }

View File

@ -5,7 +5,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/primaryBackgroundColor"> android:background="?attr/primaryBackgroundColor">
<ScrollView <androidx.core.widget.NestedScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/primaryBackgroundColor"> android:background="?attr/primaryBackgroundColor">
@ -208,8 +208,72 @@
</LinearLayout> </LinearLayout>
<LinearLayout
android:id="@+id/rateAppFrame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="25dp">
<TextView
android:id="@+id/rateApp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableStart="@drawable/ic_like"
android:drawablePadding="24dp"
android:paddingStart="12dp"
android:paddingEnd="12dp"
android:text="@string/navRate"
android:textColor="?attr/primaryTextColor"
android:textSize="16sp" />
<TextView
android:id="@+id/rateAppHintText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/rateAppHintText"
android:paddingStart="60dp"
android:paddingEnd="12dp"
android:textColor="?attr/primaryTextColor"
android:textSize="12sp" />
</LinearLayout> </LinearLayout>
</ScrollView> <LinearLayout
android:id="@+id/aboutAppFrame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="25dp">
<TextView
android:id="@+id/aboutApp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableStart="@drawable/ic_info"
android:drawablePadding="24dp"
android:paddingStart="12dp"
android:paddingEnd="12dp"
android:text="@string/navAbout"
android:textColor="?attr/primaryTextColor"
android:textSize="16sp" />
<TextView
android:id="@+id/aboutAppHintText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/aboutAppHintText"
android:paddingStart="60dp"
android:paddingEnd="12dp"
android:textColor="?attr/primaryTextColor"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</RelativeLayout> </RelativeLayout>

View File

@ -56,19 +56,6 @@
android:icon="@drawable/ic_settings" android:icon="@drawable/ic_settings"
android:title="@string/navSettings" /> android:title="@string/navSettings" />
<item android:id="@+id/nav_about"
android:icon="@drawable/ic_info"
android:title="@string/navAbout" />
</group>
<item android:id="@+id/nav_rate_app"
android:icon="@drawable/ic_like"
android:title="@string/navRate" />
<group android:checkableBehavior="single"
android:id="@+id/nav_extra">
<item android:id="@+id/nav_logout" <item android:id="@+id/nav_logout"
android:icon="@drawable/ic_logout" android:icon="@drawable/ic_logout"
android:title="@string/navLogout" /> android:title="@string/navLogout" />

View File

@ -634,6 +634,8 @@
<string name="securityHintText">SSL certificates, cache, polling delay</string> <string name="securityHintText">SSL certificates, cache, polling delay</string>
<string name="languagesHintText">Languages</string> <string name="languagesHintText">Languages</string>
<string name="reportsHintText">Crash reports</string> <string name="reportsHintText">Crash reports</string>
<string name="rateAppHintText">If you like GitNex you can give it a thumbs up</string>
<string name="aboutAppHintText">App version, build, user gitea version</string>
<string name="archivedRepository">Archived</string> <string name="archivedRepository">Archived</string>