Removed redundant ArrayList creation
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / ShareActivity.java
index 47709cb..1762430 100644 (file)
@@ -2,6 +2,7 @@
  *   ownCloud Android client application
  *
  *   @author masensio
+ *   @author David A. Velasco
  *   Copyright (C) 2015 ownCloud Inc.
  *
  *   This program is free software: you can redistribute it and/or modify
 package com.owncloud.android.ui.activity;
 
 import android.accounts.Account;
+import android.app.SearchManager;
+import android.content.Intent;
 import android.net.Uri;
 import android.os.Bundle;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentManager;
 import android.support.v4.app.FragmentTransaction;
 import android.support.v7.app.AppCompatActivity;
-import android.support.v7.widget.Toolbar;
+import android.widget.Toast;
 
 import com.owncloud.android.R;
 import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.lib.common.utils.Log_OC;
+import com.owncloud.android.providers.UsersAndGroupsSearchProvider;
 import com.owncloud.android.ui.dialog.LoadingDialog;
 import com.owncloud.android.ui.fragment.SearchFragment;
 import com.owncloud.android.ui.fragment.ShareFileFragment;
@@ -43,6 +48,8 @@ public class ShareActivity extends AppCompatActivity
         implements ShareFileFragment.OnShareFragmentInteractionListener,
         SearchFragment.OnSearchFragmentInteractionListener {
 
+    private static final String TAG = ShareActivity.class.getSimpleName();
+
     private static final String TAG_SHARE_FRAGMENT = "SHARE_FRAGMENT";
     private static final String TAG_SEARCH_FRAGMENT = "SEARCH_USER_AND_GROUPS_FRAGMENT";
 
@@ -94,6 +101,48 @@ public class ShareActivity extends AppCompatActivity
             mSearchFragment = null;
         }
 
+        handleIntent(getIntent());
+    }
+
+
+    @Override
+    protected void onNewIntent(Intent intent) {
+        setIntent(intent);
+        handleIntent(intent);
+    }
+
+
+    private void handleIntent(Intent intent) {
+        // Verify the action and get the query
+        if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
+            String query = intent.getStringExtra(SearchManager.QUERY);
+            doMySearch(query);
+
+        } else if (UsersAndGroupsSearchProvider.ACTION_SHARE_WITH.equals(intent.getAction())) {
+            Uri data = intent.getData();
+            doShareWith(
+                    data.getLastPathSegment(),
+                    UsersAndGroupsSearchProvider.DATA_GROUP.equals(data.getAuthority())
+            );
+
+        } else {
+            Log_OC.wtf(TAG, "Unexpected intent " + intent.toString());
+        }
+    }
+
+    private void doMySearch(String query) {
+        // TODO implement , or prevent that search may be sent without choosing from the suggestions list
+        Toast.makeText(this, "You want to search for [" + query + "]", Toast.LENGTH_SHORT).show();
+    }
+
+    private void doShareWith(String username, boolean isGroup) {
+        // TODO implement
+        if (isGroup) {
+            Toast.makeText(this, "You want to SHARE with GROUP [" + username + "]", Toast.LENGTH_SHORT).show();
+
+        } else {
+            Toast.makeText(this, "You want to SHARE with USER [" + username + "]", Toast.LENGTH_SHORT).show();
+        }
     }
 
     @Override