17
17
import android .os .Environment ;
18
18
import android .os .Handler ;
19
19
import android .provider .OpenableColumns ;
20
- import android .view .Menu ;
21
20
22
21
import androidx .appcompat .app .AppCompatActivity ;
23
22
import androidx .appcompat .widget .AppCompatImageButton ;
24
- import androidx .appcompat .widget .PopupMenu ;
25
23
import androidx .core .app .ActivityCompat ;
26
- import androidx .recyclerview .widget .GridLayoutManager ;
27
24
28
25
import com .google .android .material .dialog .MaterialAlertDialogBuilder ;
29
- import com .google .android .material .floatingactionbutton .FloatingActionButton ;
30
- import com .smartpack .scriptmanager .utils .AboutActivity ;
31
- import com .smartpack .scriptmanager .utils .BillingActivity ;
32
- import com .smartpack .scriptmanager .utils .FilePickerActivity ;
33
- import com .smartpack .scriptmanager .utils .RecycleViewAdapter ;
26
+ import com .smartpack .scriptmanager .activities .AboutActivity ;
27
+ import com .smartpack .scriptmanager .utils .Billing ;
34
28
import com .smartpack .scriptmanager .utils .Scripts ;
35
29
import com .smartpack .scriptmanager .utils .Utils ;
36
30
40
34
/*
41
35
* Created by sunilpaulmathew <[email protected] > on January 12, 2020
42
36
*/
43
-
44
37
public class MainActivity extends AppCompatActivity {
45
38
46
39
private boolean mExit ;
47
- private FloatingActionButton mFab ;
48
40
private Handler mHandler = new Handler ();
49
41
private String mPath ;
50
42
@@ -59,90 +51,30 @@ protected void onCreate(Bundle savedInstanceState) {
59
51
60
52
Scripts .mRecyclerView = findViewById (R .id .recycler_view );
61
53
Utils .mSettings = findViewById (R .id .settings_icon );
62
- mFab = findViewById (R .id .fab );
54
+ Utils . mFab = findViewById (R .id .fab );
63
55
AppCompatImageButton mDonate = findViewById (R .id .donate_icon );
64
56
AppCompatImageButton mInfo = findViewById (R .id .info_icon );
65
57
66
58
Utils .mSettings .setOnClickListener (v -> Utils .settingsMenu (this ));
67
59
68
- mFab .setOnClickListener (v -> {
60
+ Utils . mFab .setOnClickListener (v -> {
69
61
if (!Utils .checkWriteStoragePermission (this )) {
70
62
ActivityCompat .requestPermissions (this , new String []{
71
63
Manifest .permission .WRITE_EXTERNAL_STORAGE },1 );
72
64
Utils .snackbar (findViewById (android .R .id .content ), getString (R .string .permission_denied_write_storage ));
73
65
return ;
74
66
}
75
- showOptions ( );
67
+ Utils . fabMenu ( this );
76
68
});
77
69
78
- mDonate .setOnClickListener (v -> {
79
- Intent donations = new Intent (this , BillingActivity .class );
80
- startActivity (donations );
81
- });
70
+ mDonate .setOnClickListener (v -> Billing .showDonateOption (this ));
82
71
83
72
mInfo .setOnClickListener (v -> {
84
73
Intent aboutView = new Intent (this , AboutActivity .class );
85
74
startActivity (aboutView );
86
75
});
87
76
88
- Scripts .mRecyclerView .setLayoutManager (new GridLayoutManager (this , Utils .getSpanCount (this )));
89
- try {
90
- Scripts .mRecycleViewAdapter = new RecycleViewAdapter (Scripts .getData ());
91
- } catch (RuntimeException ignored ) {}
92
- if (Utils .checkWriteStoragePermission (this )) {
93
- Scripts .mRecyclerView .setAdapter (Scripts .mRecycleViewAdapter );
94
- } else {
95
- ActivityCompat .requestPermissions (this , new String []{
96
- Manifest .permission .WRITE_EXTERNAL_STORAGE },1 );
97
- Utils .snackbar (findViewById (android .R .id .content ), getString (R .string .permission_denied_write_storage ));
98
- }
99
- }
100
-
101
- private void showOptions () {
102
- PopupMenu popupMenu = new PopupMenu (this , mFab );
103
- Menu menu = popupMenu .getMenu ();
104
- menu .add (Menu .NONE , 0 , Menu .NONE , getString (R .string .create ));
105
- menu .add (Menu .NONE , 1 , Menu .NONE , getString (R .string .import_item ));
106
- popupMenu .setOnMenuItemClickListener (item -> {
107
- switch (item .getItemId ()) {
108
- case 0 :
109
- Utils .dialogEditText (null ,
110
- (dialogInterface , i ) -> {
111
- }, text -> {
112
- if (text .isEmpty ()) {
113
- Utils .snackbar (findViewById (android .R .id .content ), getString (R .string .name_empty ));
114
- return ;
115
- }
116
- if (!text .endsWith (".sh" )) {
117
- text += ".sh" ;
118
- }
119
- if (text .contains (" " )) {
120
- text = text .replace (" " , "_" );
121
- }
122
- if (Utils .existFile (Scripts .scriptExistsCheck (text ))) {
123
- Utils .snackbar (findViewById (android .R .id .content ), getString (R .string .script_exists , text ));
124
- return ;
125
- }
126
- Scripts .mScriptName = text ;
127
- Scripts .mScriptPath = null ;
128
- Scripts .createScript (this );
129
- }, this ).setOnDismissListener (dialogInterface -> {
130
- }).show ();
131
- break ;
132
- case 1 :
133
- if (Utils .getBoolean ("use_file_picker" , true , this )) {
134
- Intent filePicker = new Intent (this , FilePickerActivity .class );
135
- startActivity (filePicker );
136
- } else {
137
- Intent intent = new Intent (Intent .ACTION_GET_CONTENT );
138
- intent .setType ("*/*" );
139
- startActivityForResult (intent , 0 );
140
- }
141
- break ;
142
- }
143
- return false ;
144
- });
145
- popupMenu .show ();
77
+ Scripts .loadUI (this );
146
78
}
147
79
148
80
@ Override
0 commit comments