summaryrefslogtreecommitdiffstats
path: root/app/src/main/java/fr/gouv/etalab/mastodon
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/fr/gouv/etalab/mastodon')
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java14
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/activities/MediaActivity.java187
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java6
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/activities/SearchResultActivity.java17
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/activities/SearchResultTabActivity.java238
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java9
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java25
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewActivity.java7
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/ManagePollAsyncTask.java2
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/PostActionAsyncTask.java13
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveAccountsAsyncTask.java7
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java4
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveRemoteDataAsyncTask.java5
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveSearchAsyncTask.java73
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoAsyncTask.java23
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoByIDAsyncTask.java24
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/client/API.java168
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/client/APIResponse.java10
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/client/GNUAPI.java7
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/client/HttpsConnection.java1
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/client/PeertubeAPI.java39
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/drawers/ArtListAdapter.java21
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java216
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/drawers/PixelfedListAdapter.java21
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/drawers/SearchTagsAdapter.java100
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java34
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayAccountsFragment.java30
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java7
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplaySearchTagsFragment.java199
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java21
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/helper/CrossActions.java28
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java9
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/helper/SquareButton.java28
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/helper/SquareImageButton.java28
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/interfaces/OnRetrieveSearchInterface.java5
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/webview/MastalabWebViewClient.java45
36 files changed, 1330 insertions, 341 deletions
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java
index 5849c3c7e..58bf3c9a2 100644
--- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java
+++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java
@@ -1128,9 +1128,17 @@ public abstract class BaseMainActivity extends BaseActivity
//It's not a peertube search
if(displayPeertube == null){
if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
- Intent intent = new Intent(BaseMainActivity.this, SearchResultActivity.class);
- intent.putExtra("search", query);
- startActivity(intent);
+ if( (social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA)
+ && !query.contains("http://") && !query.contains("https://")){
+ Intent intent = new Intent(BaseMainActivity.this, SearchResultTabActivity.class);
+ intent.putExtra("search", query);
+ startActivity(intent);
+ }else{
+ Intent intent = new Intent(BaseMainActivity.this, SearchResultActivity.class);
+ intent.putExtra("search", query);
+ startActivity(intent);
+ }
+
}else{
Intent intent = new Intent(BaseMainActivity.this, HashTagActivity.class);
Bundle b = new Bundle();
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/MediaActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/MediaActivity.java
index a80492efa..ad76f7b3a 100644
--- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/MediaActivity.java
+++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/MediaActivity.java
@@ -23,11 +23,9 @@ import android.graphics.RectF;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
-import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
-import android.support.v7.widget.Toolbar;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
@@ -74,6 +72,7 @@ import fr.gouv.etalab.mastodon.webview.MastalabWebViewClient;
import static fr.gouv.etalab.mastodon.helper.Helper.EXTERNAL_STORAGE_REQUEST_CODE;
import static fr.gouv.etalab.mastodon.helper.Helper.THEME_BLACK;
+import static fr.gouv.etalab.mastodon.helper.Helper.THEME_LIGHT;
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
@@ -90,13 +89,14 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
private PhotoView imageView;
private SimpleExoPlayerView videoView;
private float downX;
+ private float downY;
private int mediaPosition;
MediaActivity.actionSwipe currentAction;
static final int MIN_DISTANCE = 100;
private String finalUrlDownload;
private String preview_url;
private ImageView prev, next;
- private boolean isHiding;
+ private boolean isControlElementShown = true;
private Bitmap downloadedImage;
private File fileVideo;
private TextView progress;
@@ -106,6 +106,8 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
private TextView media_description;
private Attachment attachment;
SwipeBackLayout mSwipeBackLayout;
+ private float imageScale = 0;
+ private RelativeLayout action_bar_container;
private enum actionSwipe{
RIGHT_TO_LEFT,
LEFT_TO_RIGHT,
@@ -125,8 +127,9 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
setTheme(R.style.TransparentBlack);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_media);
+ action_bar_container = (RelativeLayout) findViewById(R.id.action_bar_container);
mSwipeBackLayout = new SwipeBackLayout(MediaActivity.this);
- mSwipeBackLayout.setDirectionMode(SwipeBackLayout.FROM_BOTTOM);
+ mSwipeBackLayout.setDirectionMode(SwipeBackLayout.FROM_TOP);
mSwipeBackLayout.setMaskAlpha(125);
mSwipeBackLayout.setSwipeBackFactor(0.5f);
mSwipeBackLayout.setSwipeBackListener(new SwipeBackLayout.OnSwipeBackListener() {
@@ -162,17 +165,16 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
}
media_description = findViewById(R.id.media_description);
message_ready = findViewById(R.id.message_ready);
- Toolbar toolbar = findViewById(R.id.toolbar);
- setSupportActionBar(toolbar);
media_save = findViewById(R.id.media_save);
media_share = findViewById(R.id.media_share);
media_close = findViewById(R.id.media_close);
progress = findViewById(R.id.loader_progress);
webview_video = findViewById(R.id.webview_video);
+
media_save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- isSHaring = false;
+ isSHaring = true;
if(attachment.getType().toLowerCase().equals("video") || attachment.getType().toLowerCase().equals("gifv") || attachment.getType().toLowerCase().equals("web")) {
if( attachment != null ) {
progress.setText("0 %");
@@ -221,28 +223,6 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
finish();
}
});
- Handler h = new Handler();
- scheduleHidden = scheduleHiddenDescription = true;
- h.postDelayed(new Runnable() {
-
- @Override
- public void run() {
- // DO DELAYED STUFF
- media_close.setVisibility(View.GONE);
- media_save.setVisibility(View.GONE);
- media_share.setVisibility(View.GONE);
- scheduleHidden = false;
- }
- }, 2000);
- h.postDelayed(new Runnable() {
-
- @Override
- public void run() {
- // DO DELAYED STUFF
- media_description.setVisibility(View.GONE);
- scheduleHiddenDescription = false;
- }
- }, 6000);
canSwipe = true;
loader = findViewById(R.id.loader);
imageView = findViewById(R.id.media_picture);
@@ -252,9 +232,12 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
if( theme == THEME_BLACK){
changeDrawableColor(getApplicationContext(), prev, R.color.dark_icon);
changeDrawableColor(getApplicationContext(), next, R.color.dark_icon);
- }else {
+ }else if(theme == THEME_LIGHT) {
changeDrawableColor(getApplicationContext(), prev, R.color.mastodonC4);
changeDrawableColor(getApplicationContext(), next, R.color.mastodonC4);
+ }else{
+ changeDrawableColor(getApplicationContext(), prev, R.color.white);
+ changeDrawableColor(getApplicationContext(), next, R.color.white);
}
prev.setOnClickListener(new View.OnClickListener() {
@Override
@@ -275,18 +258,28 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
imageView.setOnMatrixChangeListener(new OnMatrixChangedListener() {
@Override
public void onMatrixChanged(RectF rect) {
+ imageScale = imageView.getScale();
canSwipe = (imageView.getScale() == 1 );
mSwipeBackLayout.isDisabled(imageView.getScale() != 1 );
}
});
+ if( attachments != null && attachments.size() > 1){
+ prev.setVisibility(View.VISIBLE);
+ next.setVisibility(View.VISIBLE);
+ }
pbar_inf = findViewById(R.id.pbar_inf);
setTitle("");
- isHiding = false;
+ //isHiding = false;
setTitle("");
displayMediaAtPosition(actionSwipe.POP);
}
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ outState.putFloat("scale", imageScale);
+ super.onSaveInstanceState(outState);
+ }
/**
@@ -297,75 +290,69 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
*/
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
-
- if( event.getAction() == MotionEvent.ACTION_DOWN && !scheduleHidden){
- scheduleHidden = true;
- media_close.setVisibility(View.VISIBLE);
- media_save.setVisibility(View.VISIBLE);
- media_share.setVisibility(View.VISIBLE);
- Handler handler = new Handler();
- handler.postDelayed(new Runnable() {
- @Override
- public void run() {
- media_close.setVisibility(View.GONE);
- media_save.setVisibility(View.GONE);
- media_share.setVisibility(View.GONE);
- scheduleHidden = false;
- }
- }, 2000);
- }
- if( event.getAction() == MotionEvent.ACTION_DOWN && !scheduleHiddenDescription){
- scheduleHiddenDescription = true;
- if( attachment != null && attachment.getDescription() != null && !attachment.getDescription().equals("null")){
- media_description.setText(attachment.getDescription());
- media_description.setVisibility(View.VISIBLE);
- imageView.setContentDescription(attachment.getDescription());
- }else{
- media_description.setText("");
- media_description.setVisibility(View.GONE);
- }
- Handler handler = new Handler();
- handler.postDelayed(new Runnable() {
- @Override
- public void run() {
- media_description.setVisibility(View.GONE);
- scheduleHiddenDescription = false;
- }
- }, 6000);
- }
- if( !canSwipe || mediaPosition > attachments.size() || mediaPosition < 1 || attachments.size() <= 1)
- return super.dispatchTouchEvent(event);
+ Boolean thisControllShown = isControlElementShown;
switch(event.getAction()){
case MotionEvent.ACTION_DOWN: {
downX = event.getX();
+ downY = event.getY();
//Displays navigation left/right buttons
- if( attachments != null && attachments.size() > 1 && !isHiding){
- prev.setVisibility(View.VISIBLE);
- next.setVisibility(View.VISIBLE);
- isHiding = true;
- new Handler().postDelayed(new Runnable(){
- public void run() {
- prev.setVisibility(View.GONE);
- next.setVisibility(View.GONE);
- isHiding = false;
- }
- }, 2000);
+ if( attachments != null && attachments.size() > 1){
+ if(thisControllShown){
+ prev.setVisibility(View.GONE);
+ next.setVisibility(View.GONE);
+ }else{
+ prev.setVisibility(View.VISIBLE);
+ next.setVisibility(View.VISIBLE);
+ }
}
return super.dispatchTouchEvent(event);
}
case MotionEvent.ACTION_UP: {
float upX = event.getX();
float deltaX = downX - upX;
+ float upY = event.getY();
+ float deltaY = downY - upY;
// swipe horizontal
-
if( downX > MIN_DISTANCE & (Math.abs(deltaX) > MIN_DISTANCE ) ){
+ if( !canSwipe || mediaPosition > attachments.size() || mediaPosition < 1 || attachments.size() <= 1)
+ return super.dispatchTouchEvent(event);
if(deltaX < 0) { switchOnSwipe(MediaActivity.actionSwipe.LEFT_TO_RIGHT); return true; }
if(deltaX > 0) { switchOnSwipe(MediaActivity.actionSwipe.RIGHT_TO_LEFT); return true; }
- }else{
+ }else if(downY > MIN_DISTANCE & (Math.abs(deltaY) > MIN_DISTANCE ) ){
+ if(deltaY > 0) { finish(); return true; }
+ if(deltaY < 0) { finish(); return true; }
+ } else {
currentAction = MediaActivity.actionSwipe.POP;
+ isControlElementShown = !isControlElementShown;
+ if (thisControllShown) {
+ if(event.getY() > action_bar_container.getHeight()) {
+ FullScreencall(thisControllShown);
+ action_bar_container.setVisibility(View.GONE);
+ if (media_description.getVisibility() == View.VISIBLE) {
+ media_description.setVisibility(View.GONE);
+ }
+ }
+ } else {
+ action_bar_container.setVisibility(View.VISIBLE);
+ FullScreencall(thisControllShown);
+ if (attachment != null && attachment.getDescription() != null && !attachment.getDescription().equals("null")) {
+ media_description.setText(attachment.getDescription());
+ media_description.setVisibility(View.VISIBLE);
+ imageView.setContentDescription(attachment.getDescription());
+ } else {
+ media_description.setText("");
+ media_description.setVisibility(View.GONE);
+ }
+ }
+
+
}
}
+
}
+
+
+
return super.dispatchTouchEvent(event);
}
@@ -561,20 +548,46 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
@Override
public void onResume(){
super.onResume();
- FullScreencall();
if( player != null) {
player.setPlayWhenReady(true);
}
}
- public void FullScreencall() {
+
+ @Override
+ protected void onPostResume() {
+ super.onPostResume();
+ FullScreencall(false);
+ }
+
+ public void FullScreencall(Boolean shouldFullscreen) {
if(Build.VERSION.SDK_INT < 19) {
View v = this.getWindow().getDecorView();
- v.setSystemUiVisibility(View.GONE);
+ if(shouldFullscreen){
+ v.setSystemUiVisibility(View.GONE);
+ }else {
+ v.setSystemUiVisibility(View.VISIBLE);
+ }
} else {
View decorView = getWindow().getDecorView();
- int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
- decorView.setSystemUiVisibility(uiOptions);
+ if(shouldFullscreen){
+ decorView.setSystemUiVisibility(
+ View.SYSTEM_UI_FLAG_IMMERSIVE
+ // Set the content to appear under the system bars so that the
+ // content doesn't resize when the system bars hide and show.
+ | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
+ | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
+ | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+ // Hide the nav bar and status bar
+ | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
+ | View.SYSTEM_UI_FLAG_FULLSCREEN
+ | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
+ }else{
+ decorView.setSystemUiVisibility(
+ View.SYSTEM_UI_FLAG_LAYOUT_STABLE
+ | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
+ | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
+ }
}
}
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java
index 2e9539b51..04fb25e19 100644
--- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java
+++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java
@@ -383,9 +383,9 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
protected Void doInBackground(Void... voids) {
if (peertube != null) {
- Results search = new API(contextReference.get()).search("https://" + peertube.getAccount().getHost() + "/videos/watch/" + peertube.getUuid());
- if (search != null) {
- remoteStatuses = search.getStatuses();
+ APIResponse search = new API(contextReference.get()).search("https://" + peertube.getAccount().getHost() + "/videos/watch/" + peertube.getUuid());
+ if (search != null && search.getResults() != null) {
+ remoteStatuses = search.getResults().getStatuses();
}
}
return null;
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/SearchResultActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/SearchResultActivity.java
index 9d3bcd608..28152f00f 100644
--- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/SearchResultActivity.java
+++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/SearchResultActivity.java
@@ -139,21 +139,24 @@ public class SearchResultActivity extends BaseActivity implements OnRetrieveSear
@Override
- public void onRetrieveSearch(Results results, Error error) {
+ public void onRetrieveSearch(APIResponse apiResponse) {
loader.setVisibility(View.GONE);
- if( error != null){
- Toasty.error(getApplicationContext(), error.getError(),Toast.LENGTH_LONG).show();
+ if( apiResponse.getError() != null){
+ if( apiResponse.getError().getError() != null)
+ Toasty.error(getApplicationContext(), apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
+ else
+ Toasty.error(getApplicationContext(), getString(R.string.toast_error),Toast.LENGTH_LONG).show();
return;
}
- if( results == null || (results.getAccounts().size() == 0 && results.getStatuses().size() == 0 && results.getHashtags().size() == 0)){
+ if( apiResponse.getResults() == null || ( apiResponse.getResults().getAccounts().size() == 0 && apiResponse.getResults().getStatuses().size() == 0 && apiResponse.getResults().getHashtags().size() == 0)){
RelativeLayout no_result = findViewById(R.id.no_result);
no_result.setVisibility(View.VISIBLE);
return;
}
lv_search.setVisibility(View.VISIBLE);
- List<String> tags = results.getHashtags();
- List<Account> accounts = results.getAccounts();
- List<Status> statuses = results.getStatuses();
+ List<String> tags = apiResponse.getResults().getHashtags();
+ List<Account> accounts = apiResponse.getResults().getAccounts();
+ List<Status> statuses = apiResponse.getResults().getStatuses();
SearchListAdapter searchListAdapter = new SearchListAdapter(SearchResultActivity.this, statuses, accounts, tags);
lv_search.setAdapter(searchListAdapter);
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/SearchResultTabActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/SearchResultTabActivity.java
new file mode 100644
index 000000000..e79de957c
--- /dev/null
+++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/SearchResultTabActivity.java
@@ -0,0 +1,238 @@
+/* Copyright 2019 Thomas Schneider
+ *
+ * This file is a part of Mastalab
+ *
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
+ * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+ * Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with Mastalab; if not,
+ * see <http://www.gnu.org/licenses>. */
+package fr.gouv.etalab.mastodon.activities;
+
+import android.annotation.SuppressLint;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.support.design.widget.TabLayout;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.app.FragmentStatePagerAdapter;
+import android.support.v4.view.PagerAdapter;
+import android.support.v4.view.ViewPager;
+import android.support.v7.app.ActionBar;
+import android.support.v7.widget.Toolbar;
+import android.view.LayoutInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import es.dmoral.toasty.Toasty;
+import fr.gouv.etalab.mastodon.R;
+import fr.gouv.etalab.mastodon.asynctasks.RetrieveAccountsAsyncTask;
+import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
+import fr.gouv.etalab.mastodon.asynctasks.RetrieveSearchAsyncTask;
+import fr.gouv.etalab.mastodon.fragments.DisplayAccountsFragment;
+import fr.gouv.etalab.mastodon.fragments.DisplaySearchTagsFragment;
+import fr.gouv.etalab.mastodon.fragments.DisplayStatusFragment;
+import fr.gouv.etalab.mastodon.helper.Helper;
+
+import static fr.gouv.etalab.mastodon.helper.Helper.THEME_LIGHT;
+
+
+/**
+ * Created by Thomas on 31/03/2019.
+ * Show search results within tabs
+ */
+
+public class SearchResultTabActivity extends BaseActivity {
+
+
+ private String search;
+ private TabLayout tabLayout;
+ private ViewPager search_viewpager;
+ private DisplayStatusFragment displayStatusFragment;
+
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
+ int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
+ switch (theme){
+ case Helper.THEME_LIGHT:
+ setTheme(R.style.AppTheme);
+ break;
+ case Helper.THEME_DARK:
+ setTheme(R.style.AppThemeDark);
+ break;
+ case Helper.THEME_BLACK:
+ setTheme(R.style.AppThemeBlack);
+ break;
+ default:
+ setTheme(R.style.AppThemeDark);
+ }
+
+ setContentView(R.layout.activity_search_result_tabs);
+
+
+ Bundle b = getIntent().getExtras();
+ if(b != null){
+ search = b.getString("search");
+ if( search == null)
+ Toasty.error(this,getString(R.string.toast_error_search), Toast.LENGTH_LONG).show();
+ }else{
+ Toasty.error(this,getString(R.string.toast_error_search),Toast.LENGTH_LONG).show();
+ }
+ if( search == null)
+ finish();
+
+ tabLayout = findViewById(R.id.search_tabLayout);
+ search_viewpager = findViewById(R.id.search_viewpager);
+
+
+ if( getSupportActionBar() != null)
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ ActionBar actionBar = getSupportActionBar();
+ if( actionBar != null ) {
+ LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ assert inflater != null;
+ @SuppressLint("InflateParams") View view = inflater.inflate(R.layout.simple_bar, null);
+ actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+ actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
+ ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
+ TextView toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title);
+ toolbar_close.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ finish();
+ }
+ });
+ toolbar_title.setText(search);
+ if (theme == THEME_LIGHT){
+ Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
+ Helper.colorizeToolbar(toolbar, R.color.black, SearchResultTabActivity.this);
+ }
+ }
+ setTitle(search);
+ tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.tags)));
+ tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.accounts)));
+ tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.toots)));
+
+ PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
+ search_viewpager.setAdapter(mPagerAdapter);
+
+ search_viewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
+ @Override
+ public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
+
+ }
+
+ @Override
+ public void onPageSelected(int position) {
+ TabLayout.Tab tab = tabLayout.getTabAt(position);
+ if( tab != null)
+ tab.select();
+ }
+