New tablayout for profiles

This commit is contained in:
stom79 2018-09-05 10:19:07 +02:00
parent 930bcb393a
commit 2f96096f24
9 changed files with 244 additions and 20 deletions

View File

@ -74,7 +74,7 @@ dependencies {
implementation "ch.acra:acra-mail:$acraVersion"
implementation "ch.acra:acra-dialog:$acraVersion"
implementation "ch.acra:acra-limiter:$acraVersion"
implementation "com.veinhorn.scrollgalleryview:library:1.0.8"
playstoreImplementation "io.github.kobakei:ratethisapp:$ratethisappLibraryVersion"

View File

@ -16,6 +16,7 @@
see <http://www.gnu.org/licenses>
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="auto"
package="fr.gouv.etalab.mastodon">
@ -29,6 +30,7 @@
<application
android:name=".activities.MainApplication"
android:allowBackup="false"
tools:replace="android:allowBackup"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:hardwareAccelerated="true"

View File

@ -79,12 +79,14 @@ import fr.gouv.etalab.mastodon.asynctasks.RetrieveRelationshipAsyncTask;
import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.APIResponse;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.Attachment;
import fr.gouv.etalab.mastodon.client.Entities.Error;
import fr.gouv.etalab.mastodon.client.Entities.Status;
import fr.gouv.etalab.mastodon.client.HttpsConnection;
import fr.gouv.etalab.mastodon.drawers.StatusListAdapter;
import fr.gouv.etalab.mastodon.fragments.DisplayAccountsFragment;
import fr.gouv.etalab.mastodon.fragments.DisplayStatusFragment;
import fr.gouv.etalab.mastodon.fragments.TabLayoutTootsFragment;
import fr.gouv.etalab.mastodon.helper.CrossActions;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
@ -753,7 +755,7 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
tabLayout.getTabAt(2).setText(getString(R.string.followers_cnt, withSuffix(account.getFollowers_count())));
//Allows to filter by long click
final LinearLayout tabStrip = (LinearLayout) tabLayout.getChildAt(0);
/*final LinearLayout tabStrip = (LinearLayout) tabLayout.getChildAt(0);
tabStrip.getChildAt(0).setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
@ -827,7 +829,7 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
popup.show();
return true;
}
});
});*/
}
@ -846,7 +848,25 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
account_pp.setImageDrawable(circularBitmapDrawable);
}
});
account_pp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(ShowAccountActivity.this, MediaActivity.class);
Bundle b = new Bundle();
Attachment attachment = new Attachment();
attachment.setDescription(account.getAcct());
attachment.setPreview_url(account.getAvatar());
attachment.setUrl(account.getAvatar());
attachment.setRemote_url(account.getAvatar());
attachment.setType("image");
ArrayList<Attachment> attachments = new ArrayList<>();
attachments.add(attachment);
intent.putParcelableArrayListExtra("mediaArray", attachments);
b.putInt("position", 1);
intent.putExtras(b);
startActivity(intent);
}
});
//Follow button
account_follow.setOnClickListener(new View.OnClickListener() {
@Override
@ -973,13 +993,10 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
Bundle bundle = new Bundle();
switch (position){
case 0:
displayStatusFragment = new DisplayStatusFragment();
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.USER);
TabLayoutTootsFragment tabLayoutTootsFragment = new TabLayoutTootsFragment();
bundle.putString("targetedId", accountId);
bundle.putBoolean("showMediaOnly",showMediaOnly);
bundle.putBoolean("showPinned",showPinned);
displayStatusFragment.setArguments(bundle);
return displayStatusFragment;
tabLayoutTootsFragment.setArguments(bundle);
return tabLayoutTootsFragment;
case 1:
DisplayAccountsFragment displayAccountsFragment = new DisplayAccountsFragment();
bundle.putSerializable("type", RetrieveAccountsAsyncTask.Type.FOLLOWING);
@ -996,7 +1013,7 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
return null;
}
@NonNull
/*@NonNull
@Override
public Object instantiateItem(ViewGroup container, int position) {
Fragment createdFragment = (Fragment) super.instantiateItem(container, position);
@ -1007,7 +1024,7 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
break;
}
return createdFragment;
}
}*/
@Override
public int getCount() {

View File

@ -17,6 +17,7 @@ package fr.gouv.etalab.mastodon.asynctasks;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.util.Log;
import java.lang.ref.WeakReference;
import java.util.List;
@ -25,6 +26,7 @@ import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.APIResponse;
import fr.gouv.etalab.mastodon.client.Entities.Status;
import fr.gouv.etalab.mastodon.helper.FilterToots;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
import fr.gouv.etalab.mastodon.sqlite.StatusCacheDAO;
@ -46,6 +48,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
private String tag;
private boolean showMediaOnly = false;
private boolean showPinned = false;
private boolean showReply = false;
private WeakReference<Context> contextReference;
private FilterToots filterToots;
private String instanceName;
@ -99,6 +102,16 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
this.showMediaOnly = showMediaOnly;
this.showPinned = showPinned;
}
public RetrieveFeedsAsyncTask(Context context, Type action, String targetedID, String max_id, boolean showMediaOnly, boolean showPinned, boolean showReply, OnRetrieveFeedsInterface onRetrieveFeedsInterface){
this.contextReference = new WeakReference<>(context);
this.action = action;
this.max_id = max_id;
this.listener = onRetrieveFeedsInterface;
this.targetedID = targetedID;
this.showMediaOnly = showMediaOnly;
this.showPinned = showPinned;
this.showReply = showReply;
}
public RetrieveFeedsAsyncTask(Context context, Type action, String tag, String targetedID, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface){
this.contextReference = new WeakReference<>(context);
this.action = action;
@ -140,7 +153,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
else if (showPinned)
apiResponse = api.getPinnedStatuses(targetedID, max_id);
else
apiResponse = api.getStatus(targetedID, max_id);
apiResponse = api.getAccountTLStatuses(targetedID, max_id, !showReply);
break;
case ONESTATUS:
apiResponse = api.getStatusbyId(targetedID);

View File

@ -367,6 +367,17 @@ public class API {
return getStatus(accountId, false, true, false, max_id, null, tootPerPage);
}
/**
* Retrieves replies status(es) *synchronously*
*
* @param accountId String Id of the account
* @param max_id String id max
* @return APIResponse
*/
public APIResponse getAccountTLStatuses(String accountId, String max_id, boolean exclude_replies) {
return getStatus(accountId, false, false, exclude_replies, max_id, null, tootPerPage);
}
/**
* Retrieves status for the account *synchronously*
*
@ -383,8 +394,6 @@ public class API {
boolean exclude_replies, String max_id, String since_id, int limit) {
HashMap<String, String> params = new HashMap<>();
if( exclude_replies)
params.put("exclude_replies", Boolean.toString(true));
if (max_id != null)
params.put("max_id", max_id);
if (since_id != null)
@ -395,9 +404,9 @@ public class API {
params.put("only_media", Boolean.toString(true));
if( pinned)
params.put("pinned", Boolean.toString(true));
params.put("exclude_replies", Boolean.toString(exclude_replies));
params.put("limit", String.valueOf(limit));
statuses = new ArrayList<>();
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
String response = httpsConnection.get(getAbsoluteUrl(String.format("/accounts/%s/statuses", accountId)), 60, params, prefKeyOauthTokenT);

View File

@ -19,6 +19,8 @@ import android.database.sqlite.SQLiteDatabase;
import android.os.Build;
import android.text.Html;
import android.text.SpannableString;
import android.util.Log;
import com.google.common.io.ByteStreams;
import org.json.JSONObject;
import java.io.BufferedInputStream;

View File

@ -74,7 +74,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
private String targetedId;
private String tag;
private RecyclerView lv_status;
private boolean showMediaOnly, showPinned;
private boolean showMediaOnly, showPinned, showReply;
private Intent streamingFederatedIntent, streamingLocalIntent;
LinearLayoutManager mLayoutManager;
boolean firstTootsLoaded;
@ -96,12 +96,14 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
//Will allow to load first toots if bookmark != null
firstTootsLoaded = true;
showPinned = false;
showReply = false;
if (bundle != null) {
type = (RetrieveFeedsAsyncTask.Type) bundle.get("type");
targetedId = bundle.getString("targetedId", null);
tag = bundle.getString("tag", null);
showMediaOnly = bundle.getBoolean("showMediaOnly",false);
showPinned = bundle.getBoolean("showPinned",false);
showReply = bundle.getBoolean("showReply",false);
remoteInstance = bundle.getString("remote_instance", "");
}
isSwipped = false;
@ -150,7 +152,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
if(!flag_loading ) {
flag_loading = true;
if( type == RetrieveFeedsAsyncTask.Type.USER)
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, showPinned, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, showPinned, showReply, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else if( type == RetrieveFeedsAsyncTask.Type.TAG)
asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else if( type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE )
@ -209,7 +211,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
}
if( context != null) {
if (type == RetrieveFeedsAsyncTask.Type.USER)
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, showPinned, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, showPinned, showReply,DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else if (type == RetrieveFeedsAsyncTask.Type.TAG)
asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else if( type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE )
@ -233,7 +235,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
public void run() {
if( context != null){
if (type == RetrieveFeedsAsyncTask.Type.USER)
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, showPinned, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, showPinned, showReply,DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else if (type == RetrieveFeedsAsyncTask.Type.TAG)
asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else if( type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE )

View File

@ -0,0 +1,142 @@
package fr.gouv.etalab.mastodon.fragments;
/* Copyright 2018 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>. */
import android.os.Bundle;
import android.support.annotation.NonNull;
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.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import fr.gouv.etalab.mastodon.R;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
import fr.gouv.etalab.mastodon.helper.Helper;
/**
* Created by Thomas on 05/09/2018.
* Tablayout selection for toots in a profile
*/
public class TabLayoutTootsFragment extends Fragment {
private String targetedId;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View inflatedView = inflater.inflate(R.layout.tablayout_toots, container, false);
TabLayout tabLayout = inflatedView.findViewById(R.id.tabLayout);
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.toots)));
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.replies)));
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.media)));
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.pinned_toots)));
final ViewPager viewPager = inflatedView.findViewById(R.id.viewpager);
Bundle bundle = this.getArguments();
if (bundle != null) {
this.targetedId = bundle.getString("targetedId", null);
}
viewPager.setAdapter(new PagerAdapter
(getChildFragmentManager(), tabLayout.getTabCount()));
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
return inflatedView;
}
/**
* Page Adapter for settings
*/
private class PagerAdapter extends FragmentStatePagerAdapter {
int mNumOfTabs;
private PagerAdapter(FragmentManager fm, int NumOfTabs) {
super(fm);
this.mNumOfTabs = NumOfTabs;
}
@Override
public Fragment getItem(int position) {
Log.v(Helper.TAG,"position: " + position);
switch (position) {
case 0:
DisplayStatusFragment displayStatusFragment = new DisplayStatusFragment();
Bundle bundle = new Bundle();
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.USER);
bundle.putString("targetedId", targetedId);
bundle.putBoolean("showReply",false);
displayStatusFragment.setArguments(bundle);
return displayStatusFragment;
case 1:
displayStatusFragment = new DisplayStatusFragment();
bundle = new Bundle();
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.USER);
bundle.putString("targetedId", targetedId);
bundle.putBoolean("showReply",true);
displayStatusFragment.setArguments(bundle);
return displayStatusFragment;
case 2:
displayStatusFragment = new DisplayStatusFragment();
bundle = new Bundle();
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.USER);
bundle.putString("targetedId", targetedId);
bundle.putBoolean("showMediaOnly",true);
displayStatusFragment.setArguments(bundle);
return displayStatusFragment;
case 3:
displayStatusFragment = new DisplayStatusFragment();
bundle = new Bundle();
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.USER);
bundle.putString("targetedId", targetedId);
bundle.putBoolean("showPinned",true);
displayStatusFragment.setArguments(bundle);
return displayStatusFragment;
default:
displayStatusFragment = new DisplayStatusFragment();
return displayStatusFragment;
}
}
@Override
public int getCount() {
return mNumOfTabs;
}
}
}

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2018 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>.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
app:tabGravity="fill"
app:tabMaxWidth="0dp"
android:layout_height="wrap_content"
/>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="70dp"
/>
</LinearLayout>