1+ /*
2+ * Copyright (C) 2021-2022 sunilpaulmathew <sunil.kde@gmail.com>
3+ *
4+ * This file is part of Script Manager, an app to create, import, edit
5+ * and easily execute any properly formatted shell scripts.
6+ *
7+ */
8+
9+ package com .smartpack .scriptmanager .activities ;
10+
11+ import android .annotation .SuppressLint ;
12+ import android .content .Intent ;
13+ import android .graphics .Color ;
14+ import android .net .Uri ;
15+ import android .os .Bundle ;
16+ import android .provider .Settings ;
17+ import android .widget .LinearLayout ;
18+
19+ import androidx .annotation .Nullable ;
20+ import androidx .appcompat .app .AppCompatActivity ;
21+ import androidx .appcompat .widget .AppCompatImageButton ;
22+ import androidx .recyclerview .widget .DividerItemDecoration ;
23+ import androidx .recyclerview .widget .LinearLayoutManager ;
24+ import androidx .recyclerview .widget .RecyclerView ;
25+
26+ import com .google .android .material .dialog .MaterialAlertDialogBuilder ;
27+ import com .google .android .material .textview .MaterialTextView ;
28+ import com .smartpack .scriptmanager .BuildConfig ;
29+ import com .smartpack .scriptmanager .R ;
30+ import com .smartpack .scriptmanager .adapters .RecycleViewSettingsAdapter ;
31+ import com .smartpack .scriptmanager .utils .AppSettings ;
32+ import com .smartpack .scriptmanager .utils .Billing ;
33+ import com .smartpack .scriptmanager .utils .RecycleViewItem ;
34+ import com .smartpack .scriptmanager .utils .Utils ;
35+
36+ import java .util .ArrayList ;
37+
38+ /*
39+ * Created by sunilpaulmathew <sunil.kde@gmail.com> on February 13, 2020
40+ */
41+ public class SettingsActivity extends AppCompatActivity {
42+
43+ private ArrayList <RecycleViewItem > mData = new ArrayList <>();
44+
45+ @ SuppressLint ({"SetTextI18n" , "UseCompatLoadingForDrawables" })
46+ @ Override
47+ protected void onCreate (@ Nullable Bundle savedInstanceState ) {
48+ super .onCreate (savedInstanceState );
49+ setContentView (R .layout .activity_settings );
50+
51+ AppCompatImageButton mBack = findViewById (R .id .back_button );
52+ LinearLayout mAppInfo = findViewById (R .id .app_info );
53+ MaterialTextView mAppTitle = findViewById (R .id .title );
54+ MaterialTextView mAppDescription = findViewById (R .id .description );
55+ RecyclerView mRecyclerView = findViewById (R .id .recycler_view );
56+
57+ mAppTitle .setText (getString (R .string .app_name ) + (Utils .isProUser (this ) ? " Pro " : " " ) + BuildConfig .VERSION_NAME );
58+ mAppTitle .setTextColor (Utils .isDarkTheme (this ) ? Color .WHITE : Color .BLACK );
59+ mAppDescription .setText (BuildConfig .APPLICATION_ID );
60+
61+ mRecyclerView .setLayoutManager (new LinearLayoutManager (this ));
62+ mRecyclerView .addItemDecoration (new DividerItemDecoration (this , DividerItemDecoration .VERTICAL ));
63+ RecycleViewSettingsAdapter mRecycleViewAdapter = new RecycleViewSettingsAdapter (mData );
64+ mRecyclerView .setAdapter (mRecycleViewAdapter );
65+
66+ mAppInfo .setOnClickListener (v -> {
67+ Intent settings = new Intent (Settings .ACTION_APPLICATION_DETAILS_SETTINGS );
68+ settings .addFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
69+ Uri uri = Uri .fromParts ("package" , BuildConfig .APPLICATION_ID , null );
70+ settings .setData (uri );
71+ startActivity (settings );
72+ finish ();
73+ });
74+
75+ mData .add (new RecycleViewItem (getString (R .string .language ), AppSettings .getLanguage (this ), getResources ().getDrawable (R .drawable .ic_language ), null ));
76+ mData .add (new RecycleViewItem (getString (R .string .file_picker ), getString (Utils .getBoolean ("use_file_picker" , true , this ) ? R .string .file_picker_inbuilt
77+ : R .string .file_picker_external ), getResources ().getDrawable (R .drawable .ic_folder ), null ));
78+ mData .add (new RecycleViewItem (getString (R .string .dark_theme ), AppSettings .getAppThemeDescription (this ), getResources ().getDrawable (R .drawable .ic_theme ), null ));
79+ mData .add (new RecycleViewItem (getString (R .string .source_code ), getString (R .string .source_code_summary ), getResources ().getDrawable (
80+ R .drawable .ic_github ), "https://github.com/SmartPack/ScriptManager" ));
81+ mData .add (new RecycleViewItem (getString (R .string .support_group ), getString (R .string .support_group_summary ), getResources ().getDrawable (R .drawable .ic_support ),
82+ "https://t.me/smartpack_kmanager" ));
83+ mData .add (new RecycleViewItem (getString (R .string .report_issue ), getString (R .string .report_issue_summary ), getResources ().getDrawable (R .drawable .ic_issue ),
84+ "https://github.com/SmartPack/ScriptManager/issues/new/choose" ));
85+ mData .add (new RecycleViewItem (getString (R .string .support_development ), null , getResources ().getDrawable (R .drawable .ic_donate ), null ));
86+ mData .add (new RecycleViewItem (getString (R .string .more_apps ), getString (R .string .more_apps_summary ), getResources ().getDrawable (
87+ R .drawable .ic_playstore ), "https://play.google.com/store/apps/dev?id=5836199813143882901" ));
88+ mData .add (new RecycleViewItem (getString (R .string .translations ), getString (R .string .translations_summary ), getResources ().getDrawable (
89+ R .drawable .ic_translate ), "https://poeditor.com/join/project?hash=w47nhsNDL7" ));
90+ mData .add (new RecycleViewItem (getString (R .string .share_app ), getString (R .string .share_app_Summary ), getResources ().getDrawable (R .drawable .ic_share ), null ));
91+ mData .add (new RecycleViewItem (getString (R .string .rate_us ), getString (R .string .rate_us_Summary ), getResources ().getDrawable (R .drawable .ic_rate ),
92+ "https://play.google.com/store/apps/details?id=com.smartpack.scriptmanager" ));
93+ mData .add (new RecycleViewItem (getString (R .string .licence ), null , getResources ().getDrawable (R .drawable .ic_licence ),
94+ "https://www.gnu.org/licenses/gpl-3.0-standalone.html" ));
95+
96+ mRecycleViewAdapter .setOnItemClickListener ((position , v ) -> {
97+ if (mData .get (position ).getUrl () != null ) {
98+ Utils .launchUrl (mData .get (position ).getUrl (), this );
99+ } else if (position == 0 ) {
100+ AppSettings .setLanguage (this );
101+ } else if (position == 1 ) {
102+ new MaterialAlertDialogBuilder (this ).setItems (getResources ().getStringArray (
103+ R .array .file_picker ), (dialogInterface , i ) -> {
104+ switch (i ) {
105+ case 0 :
106+ Utils .saveBoolean ("use_file_picker" , true , this );
107+ mData .set (position , new RecycleViewItem (getString (R .string .file_picker ), getString (R .string .file_picker_inbuilt ),
108+ getResources ().getDrawable (R .drawable .ic_folder ), null ));
109+ mRecycleViewAdapter .notifyItemChanged (position );
110+ break ;
111+ case 1 :
112+ Utils .saveBoolean ("use_file_picker" , false , this );
113+ mData .set (position , new RecycleViewItem (getString (R .string .file_picker ), getString (R .string .file_picker_external ),
114+ getResources ().getDrawable (R .drawable .ic_folder ), null ));
115+ mRecycleViewAdapter .notifyItemChanged (position );
116+ break ;
117+ }
118+ }).setOnDismissListener (dialogInterface -> {
119+ }).show ();
120+ } else if (position == 2 ) {
121+ AppSettings .setAppTheme (this );
122+ } else if (position == 6 ) {
123+ Billing .showDonateOption (this );
124+ } else if (position == 9 ) {
125+ Intent share_app = new Intent ();
126+ share_app .setAction (Intent .ACTION_SEND );
127+ share_app .putExtra (Intent .EXTRA_SUBJECT , getString (R .string .app_name ));
128+ share_app .putExtra (Intent .EXTRA_TEXT , getString (R .string .share_message_app , BuildConfig .VERSION_NAME ));
129+ share_app .setType ("text/plain" );
130+ Intent shareIntent = Intent .createChooser (share_app , getString (R .string .share_with ));
131+ startActivity (shareIntent );
132+ }
133+ });
134+
135+ mBack .setOnClickListener (v -> onBackPressed ());
136+ }
137+
138+ }
0 commit comments