20
20
import android .webkit .WebViewClient ;
21
21
import android .widget .AdapterView ;
22
22
import android .widget .Toast ;
23
- import android .widget .ViewFlipper ;
24
23
25
24
import com .google .gson .JsonObject ;
26
25
import com .google .gson .JsonParser ;
32
31
33
32
import androidx .annotation .NonNull ;
34
33
import androidx .annotation .Nullable ;
35
- import androidx .annotation .RequiresApi ;
36
34
import androidx .appcompat .widget .AppCompatSpinner ;
37
35
import androidx .databinding .ViewDataBinding ;
38
36
46
44
import io .syslogic .github .R ;
47
45
import io .syslogic .github .Constants ;
48
46
import io .syslogic .github .databinding .FragmentRepositoryBinding ;
47
+ import io .syslogic .github .dialog .ProgressDialogFragment ;
49
48
import io .syslogic .github .model .User ;
50
49
import io .syslogic .github .network .TokenCallback ;
51
50
import io .syslogic .github .retrofit .GithubClient ;
64
63
*
65
64
* @author Martin Zeitler
66
65
*/
67
- public class RepositoryFragment extends BaseFragment implements TokenCallback , ProgressMonitor {
66
+ public class RepositoryFragment extends BaseFragment implements TokenCallback {
68
67
69
68
/** Log Tag */
70
69
@ SuppressWarnings ("unused" )
@@ -74,8 +73,8 @@ public class RepositoryFragment extends BaseFragment implements TokenCallback, P
74
73
75
74
/** Data Binding */
76
75
FragmentRepositoryBinding mDataBinding ;
77
-
78
- private Long itemId = 0L ;
76
+ ProgressDialogFragment currentDialog ;
77
+ Long itemId = 0L ;
79
78
80
79
/** Constructor */
81
80
public RepositoryFragment () {}
@@ -90,7 +89,6 @@ public static RepositoryFragment newInstance(long itemId) {
90
89
}
91
90
92
91
@ Override
93
- @ RequiresApi (api = Build .VERSION_CODES .N )
94
92
public void onCreate (@ Nullable Bundle savedInstanceState ) {
95
93
super .onCreate (savedInstanceState );
96
94
this .registerBroadcastReceiver ();
@@ -169,16 +167,17 @@ public void onNothingSelected(AdapterView<?> parent) {}
169
167
// directory should be empty.
170
168
if (destination .exists ()) {
171
169
if (! destination .delete ()) {
172
- Log .e (LOG_TAG , "destination not deleted" );
170
+ Log .e (LOG_TAG , "destination directory not deleted" );
173
171
return ;
174
172
}
175
173
}
176
174
if (! destination .exists ()) {
177
175
if (! destination .mkdir ()) {
178
- Log .e (LOG_TAG , "destination not created" );
176
+ Log .e (LOG_TAG , "destination directory not created" );
177
+ return ;
179
178
}
180
179
}
181
- if (destination .exists ()) {
180
+ if (destination .exists () && destination . isDirectory () ) {
182
181
String branch = getDataBinding ().toolbarDownload .spinnerBranch .getSelectedItem ().toString ();
183
182
gitClone (destination , branch );
184
183
}
@@ -190,11 +189,17 @@ public void onNothingSelected(AdapterView<?> parent) {}
190
189
191
190
/** git clone. */
192
191
private void gitClone (@ NonNull File destination , @ Nullable String branch ) {
192
+
193
+ /* Attempting to display the checkout progress. */
194
+ this .currentDialog = new ProgressDialogFragment ();
195
+ this .currentDialog .show (getChildFragmentManager (), ProgressDialogFragment .LOG_TAG );
196
+ this .currentDialog .setRepositoryName (getRepoName ());
197
+
193
198
Thread thread = new Thread (() -> {
194
199
CloneCommand cmd = Git .cloneRepository ()
195
200
.setURI (getRepoUrl ())
196
201
.setCredentialsProvider (new UsernamePasswordCredentialsProvider (getPersonalAccessToken (), "" ))
197
- .setProgressMonitor (RepositoryFragment . this )
202
+ .setProgressMonitor (( ProgressMonitor ) currentDialog )
198
203
.setDirectory (destination )
199
204
.setRemote ("github" );
200
205
@@ -204,19 +209,16 @@ private void gitClone(@NonNull File destination, @Nullable String branch) {
204
209
cmd .setBranch (branch );
205
210
}
206
211
212
+ if (mDebug ) {Log .d (LOG_TAG , "Cloning into " + getRepoName () + "..." );}
207
213
try {
208
- if (mDebug ) {Log .d (LOG_TAG , "Cloning into " + getRepoName () + "..." );}
209
214
cmd .call ();
210
215
} catch (GitAPIException | JGitInternalException | NoSuchMethodError e ) {
211
216
String message = e .getMessage ();
212
217
if (mDebug ) {Log .e (LOG_TAG , e .getMessage (), e );}
213
- requireActivity ().runOnUiThread (() ->
214
- Toast .makeText (requireContext (), message , Toast .LENGTH_LONG ).show ());
215
- } finally {
216
- String message = "Cloned." ;
217
- if (mDebug ) {Log .d (LOG_TAG , message );}
218
- requireActivity ().runOnUiThread (() ->
219
- Toast .makeText (requireContext (), message , Toast .LENGTH_LONG ).show ());
218
+ requireActivity ().runOnUiThread (() -> {
219
+ this .currentDialog .dismiss ();
220
+ Toast .makeText (requireContext (), message , Toast .LENGTH_LONG ).show ();
221
+ });
220
222
}
221
223
});
222
224
thread .start ();
@@ -538,47 +540,6 @@ public void showDownloads() {
538
540
startActivity (intent );
539
541
}
540
542
541
- @ SuppressWarnings ("unused" )
542
- private void switchToolbarView (@ NonNull Integer childIndex ) {
543
- ViewFlipper view = this .mDataBinding .toolbarDownload .viewflipperDownload ;
544
- int index = view .getDisplayedChild ();
545
- switch (childIndex ) {
546
- case 0 : if (index != childIndex ) {view .showPrevious ();} break ;
547
- case 1 : if (index != childIndex ) {view .showNext ();} break ;
548
- }
549
- }
550
-
551
543
@ Override
552
544
public void onLogin (@ NonNull User item ) {}
553
-
554
- /** Interface: ProgressMonitor */
555
- @ Override
556
- public void start (int totalTasks ) {
557
- if (mDebug ) {Log .d (LOG_TAG , "totalTasks: " + totalTasks );}
558
- }
559
-
560
- /** Interface: ProgressMonitor */
561
- @ Override
562
- public void beginTask (String title , int totalWork ) {
563
- if (mDebug ) {Log .d (LOG_TAG , "beginTask " + title + ": " + totalWork );}
564
- }
565
-
566
- /** Interface: ProgressMonitor */
567
- @ Override
568
- public void update (int completed ) {
569
- if (mDebug ) {Log .d (LOG_TAG , "completed: +" + completed );}
570
- }
571
-
572
- /** Interface: ProgressMonitor */
573
- @ Override
574
- public void endTask () {
575
- if (mDebug ) {Log .d (LOG_TAG , "endTask" );}
576
- }
577
-
578
- /** Interface: ProgressMonitor */
579
- @ Override
580
- public boolean isCancelled () {
581
- // if (mDebug) {Log.d(LOG_TAG, "isCancelled?");}
582
- return false ;
583
- }
584
545
}
0 commit comments