2626import android .content .Intent ;
2727import android .content .res .ColorStateList ;
2828import android .content .res .Resources ;
29- import android .graphics .Color ;
3029import android .graphics .drawable .GradientDrawable ;
3130import android .net .Uri ;
3231import android .os .Bundle ;
3332import android .text .TextUtils ;
3433import android .util .DisplayMetrics ;
3534import android .util .Log ;
36- import android .view .Menu ;
3735import android .view .View ;
38- import android .widget .ImageView ;
39- import android .widget .LinearLayout ;
40- import android .widget .TextView ;
4136
4237import androidx .activity .OnBackPressedCallback ;
4338import androidx .annotation .ColorInt ;
4641import androidx .appcompat .app .ActionBarDrawerToggle ;
4742import androidx .appcompat .view .ActionMode ;
4843import androidx .appcompat .widget .SearchView ;
49- import androidx .constraintlayout .widget .ConstraintLayout ;
5044import androidx .coordinatorlayout .widget .CoordinatorLayout ;
5145import androidx .core .app .ActivityCompat ;
5246import androidx .core .content .ContextCompat ;
6761import com .google .android .material .dialog .MaterialAlertDialogBuilder ;
6862import com .google .android .material .floatingactionbutton .FloatingActionButton ;
6963import com .google .android .material .snackbar .Snackbar ;
64+ import com .nextcloud .android .common .core .utils .ecosystem .AccountReceiverCallback ;
65+ import com .nextcloud .android .common .core .utils .ecosystem .EcosystemApp ;
66+ import com .nextcloud .android .common .core .utils .ecosystem .EcosystemManager ;
7067import com .nextcloud .android .common .ui .theme .utils .ColorRole ;
7168import com .nextcloud .android .sso .AccountImporter ;
7269import com .nextcloud .android .sso .exceptions .AccountImportCancelledException ;
7673import com .nextcloud .android .sso .exceptions .TokenMismatchException ;
7774import com .nextcloud .android .sso .exceptions .UnknownErrorException ;
7875import com .nextcloud .android .sso .helper .SingleAccountHelper ;
76+ import com .owncloud .android .lib .common .utils .Log_OC ;
77+
78+ import org .jetbrains .annotations .NotNull ;
7979
8080import java .net .HttpURLConnection ;
81- import java .util .Arrays ;
8281import java .util .LinkedList ;
83- import java .util .List ;
8482import java .util .concurrent .ExecutorService ;
8583import java .util .concurrent .Executors ;
8684import java .util .stream .Collectors ;
8785
88- import hct .Hct ;
8986import it .niedermann .android .util .ColorUtil ;
9087import it .niedermann .owncloud .notes .LockedActivity ;
9188import it .niedermann .owncloud .notes .NotesApplication ;
121118import it .niedermann .owncloud .notes .shared .model .NavigationCategory ;
122119import it .niedermann .owncloud .notes .shared .model .NoteClickListener ;
123120import it .niedermann .owncloud .notes .shared .util .CustomAppGlideModule ;
121+ import it .niedermann .owncloud .notes .shared .util .DisplayUtils ;
124122import it .niedermann .owncloud .notes .shared .util .NoteUtil ;
125123import it .niedermann .owncloud .notes .shared .util .ShareUtil ;
126124import it .niedermann .owncloud .notes .util .LinkHelper ;
@@ -133,6 +131,8 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
133131
134132 protected MainViewModel mainViewModel ;
135133
134+ private EcosystemManager ecosystemManager ;
135+
136136 private boolean gridView = true ;
137137
138138 public static final String ADAPTER_KEY_RECENT = "recent" ;
@@ -173,6 +173,8 @@ protected void onCreate(Bundle savedInstanceState) {
173173
174174 setContentView (binding .getRoot ());
175175
176+ ecosystemManager = new EcosystemManager (this );
177+ handleEcosystemIntent (getIntent ());
176178 this .coordinatorLayout = binding .activityNotesListView .activityNotesListView ;
177179 this .swipeRefreshLayout = binding .activityNotesListView .swiperefreshlayout ;
178180 this .fabCreate = binding .activityNotesListView .fabCreate ;
@@ -379,12 +381,20 @@ private void setupDrawerAppMenu() {
379381 }
380382
381383 private void setupDrawerAppMenuListener () {
382- // Add listeners to the ecosystem items to launch the app or app-store
383- binding .drawerEcosystemFiles .setOnClickListener (v -> LinkHelper .INSTANCE .openAppOrStore (LinkHelper .APP_NEXTCLOUD_FILES , mainViewModel .getCurrentAccount ().getValue ().getAccountName (), this ));
384- binding .drawerEcosystemTalk .setOnClickListener (v -> LinkHelper .INSTANCE .openAppOrStore (LinkHelper .APP_NEXTCLOUD_TALK , mainViewModel .getCurrentAccount ().getValue ().getAccountName (), this ));
384+ binding .drawerEcosystemFiles .setOnClickListener (v -> ecosystemManager .openApp (EcosystemApp .FILES , getAccountName ()));
385+ binding .drawerEcosystemTalk .setOnClickListener (v -> ecosystemManager .openApp (EcosystemApp .TALK , getAccountName ()));
385386 binding .drawerEcosystemMore .setOnClickListener (v -> LinkHelper .INSTANCE .openAppStore ("Nextcloud" , true , this ));
386387 }
387388
389+ private String getAccountName () {
390+ final var currentAccount = mainViewModel .getCurrentAccount ().getValue ();
391+ if (currentAccount == null ) {
392+ return null ;
393+ }
394+
395+ return currentAccount .getAccountName ();
396+ }
397+
388398 private void themeDrawerAppMenu (int color ) {
389399 ColorStateList colorStateList = ColorStateList .valueOf (color );
390400 binding .drawerEcosystemFilesIcon .setImageTintList (colorStateList );
@@ -482,6 +492,26 @@ protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
482492 mainViewModel .restoreInstanceState ();
483493 }
484494
495+ private void handleEcosystemIntent (Intent intent ) {
496+ ecosystemManager .receiveAccount (intent , new AccountReceiverCallback () {
497+ @ Override
498+ public void onAccountReceived (@ NotNull String accountName ) {
499+ final var account = mainViewModel .getAccountByName (accountName );
500+ if (account != null ) {
501+ onAccountChosen (account );
502+ } else {
503+ Log_OC .w (TAG , "account not found" );
504+ DisplayUtils .showSnackMessage (MainActivity .this , R .string .account_not_found );
505+ }
506+ }
507+
508+ @ Override
509+ public void onAccountError (@ NotNull String reason ) {
510+ Log_OC .w (TAG , "handleEcosystemIntent: " + reason );
511+ }
512+ });
513+ }
514+
485515 private void setupToolbars () {
486516 setSupportActionBar (binding .activityNotesListView .searchToolbar );
487517 activityBinding .searchBar .homeToolbar .setOnClickListener ((v ) -> {
@@ -754,6 +784,7 @@ protected void onNewIntent(Intent intent) {
754784 activityBinding .searchView .setQuery (intent .getStringExtra (SearchManager .QUERY ), true );
755785 }
756786 super .onNewIntent (intent );
787+ handleEcosystemIntent (intent );
757788 }
758789
759790 @ Override
0 commit comments