Fix login + notifications
This commit is contained in:
parent
7e01c841e1
commit
0f821c8f78
|
@ -196,7 +196,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
private Stack<Integer> stackBack = new Stack<>();
|
||||
public static List<Filters> filters = new ArrayList<>();
|
||||
private DisplayStatusFragment homeFragment, federatedFragment, localFragment, artFragment;
|
||||
private DisplayNotificationsFragment notificationsFragment;
|
||||
private TabLayoutNotificationsFragment tabLayoutNotificationsFragment;
|
||||
private static final int ERROR_DIALOG_REQUEST_CODE = 97;
|
||||
|
||||
private boolean display_direct, display_local, display_global, display_art;
|
||||
|
@ -496,7 +496,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
//Only shown if the tab has focus
|
||||
if( notificationsFragment != null && notificationsFragment.getUserVisibleHint()){
|
||||
if( tabLayoutNotificationsFragment != null && tabLayoutNotificationsFragment.getUserVisibleHint()){
|
||||
PopupMenu popup = new PopupMenu(BaseMainActivity.this, tabStrip.getChildAt(1));
|
||||
popup.getMenuInflater()
|
||||
.inflate(R.menu.option_filter_notifications, popup.getMenu());
|
||||
|
@ -516,8 +516,8 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(PopupMenu menu) {
|
||||
if( notificationsFragment != null)
|
||||
notificationsFragment.refreshAll();
|
||||
if( tabLayoutNotificationsFragment != null)
|
||||
tabLayoutNotificationsFragment.refreshAll();
|
||||
}
|
||||
});
|
||||
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
|
@ -2042,8 +2042,8 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
if( lastHomeId != null && homeFragment != null){
|
||||
homeFragment.retrieveMissingToots(lastHomeId);
|
||||
}
|
||||
if( lastNotificationId != null && notificationsFragment != null){
|
||||
notificationsFragment.retrieveMissingNotifications(lastNotificationId);
|
||||
if( lastNotificationId != null && tabLayoutNotificationsFragment != null){
|
||||
tabLayoutNotificationsFragment.retrieveMissingNotifications(lastNotificationId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2482,7 +2482,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
homeFragment.setArguments(bundle);
|
||||
return homeFragment;
|
||||
} else if (position == 1) {
|
||||
TabLayoutNotificationsFragment tabLayoutNotificationsFragment = new TabLayoutNotificationsFragment();
|
||||
tabLayoutNotificationsFragment = new TabLayoutNotificationsFragment();
|
||||
return tabLayoutNotificationsFragment;
|
||||
} else {
|
||||
statusFragment = new DisplayStatusFragment();
|
||||
|
|
|
@ -16,7 +16,6 @@ package fr.gouv.etalab.mastodon.asynctasks;
|
|||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
|
@ -27,7 +26,6 @@ import fr.gouv.etalab.mastodon.client.Entities.Account;
|
|||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
import fr.gouv.etalab.mastodon.client.GNUAPI;
|
||||
import fr.gouv.etalab.mastodon.fragments.DisplayNotificationsFragment;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveNotificationsInterface;
|
||||
|
||||
|
||||
|
@ -62,7 +60,6 @@ public class RetrieveNotificationsAsyncTask extends AsyncTask<Void, Void, Void>
|
|||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
Log.v(Helper.TAG,"MainActivity.social : " + MainActivity.social );
|
||||
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
API api;
|
||||
if (account == null) {
|
||||
|
|
|
@ -134,6 +134,11 @@ public class API {
|
|||
}
|
||||
public API(Context context) {
|
||||
this.context = context;
|
||||
if( context == null) {
|
||||
APIError = new Error();
|
||||
APIError.setError(context.getString(R.string.toast_error));
|
||||
return;
|
||||
}
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
tootPerPage = sharedpreferences.getInt(Helper.SET_TOOTS_PER_PAGE, 40);
|
||||
accountPerPage = sharedpreferences.getInt(Helper.SET_ACCOUNTS_PER_PAGE, 40);
|
||||
|
|
|
@ -20,7 +20,6 @@ import android.content.SharedPreferences;
|
|||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
@ -1495,6 +1494,7 @@ public class GNUAPI {
|
|||
private APIResponse getNotifications(DisplayNotificationsFragment.Type type, String max_id, String since_id, int limit, boolean display){
|
||||
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
String stringType = null;
|
||||
if( max_id != null )
|
||||
params.put("_", max_id);
|
||||
if( since_id != null )
|
||||
|
@ -1502,16 +1502,60 @@ public class GNUAPI {
|
|||
if( 0 > limit || limit > 30)
|
||||
limit = 30;
|
||||
params.put("count",String.valueOf(limit));
|
||||
params.put("namespace","qvitter");
|
||||
List<Notification> notifications = new ArrayList<>();
|
||||
|
||||
String url = null;
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
//Current user
|
||||
String currentToken = sharedpreferences.getString(PREF_KEY_OAUTH_TOKEN, null);
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(context, db).getAccountByToken(currentToken);
|
||||
if(type == DisplayNotificationsFragment.Type.MENTION){
|
||||
params.put("name",account.getAcct());
|
||||
url = getAbsoluteUrl("/statuses/mentions_timeline.json");
|
||||
stringType = "mention";
|
||||
}else if(type == DisplayNotificationsFragment.Type.BOOST){
|
||||
url = getAbsoluteUrl("/statuses/retweets_of_me.json");
|
||||
stringType = "reblog";
|
||||
}else if(type == DisplayNotificationsFragment.Type.FOLLOW){
|
||||
url = getAbsoluteUrl("/statuses/followers.json");
|
||||
stringType = "follow";
|
||||
}
|
||||
if( url == null){
|
||||
Error error = new Error();
|
||||
error.setStatusCode(500);
|
||||
error.setError(context.getString(R.string.toast_error));
|
||||
apiResponse.setError(error);
|
||||
return apiResponse;
|
||||
}
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(getAbsoluteUrl("/qvitter/statuses/notifications.json"), 60, params, prefKeyOauthTokenT);
|
||||
Log.v(Helper.TAG,"response= " + response);
|
||||
String response = httpsConnection.get(url, 60, params, prefKeyOauthTokenT);
|
||||
apiResponse.setSince_id(httpsConnection.getSince_id());
|
||||
apiResponse.setMax_id(httpsConnection.getMax_id());
|
||||
notifications = parseNotificationResponse(new JSONArray(response));
|
||||
List<Status> statuses = parseStatuses(context, new JSONArray(response));
|
||||
List<Account> accounts = parseAccountResponse(new JSONArray(response));
|
||||
if(type == DisplayNotificationsFragment.Type.FOLLOW){
|
||||
if( accounts != null)
|
||||
for(Account st: accounts ){
|
||||
Notification notification = new Notification();
|
||||
notification.setType(stringType);
|
||||
notification.setId(st.getId());
|
||||
notification.setStatus(null);
|
||||
notification.setAccount(account);
|
||||
notifications.add(notification);
|
||||
}
|
||||
}else {
|
||||
if( statuses != null)
|
||||
for(Status st: statuses ){
|
||||
Notification notification = new Notification();
|
||||
notification.setType(stringType);
|
||||
notification.setId(st.getId());
|
||||
notification.setStatus(st);
|
||||
notification.setAccount(st.getAccount());
|
||||
notifications.add(notification);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
e.printStackTrace();
|
||||
|
@ -1865,7 +1909,10 @@ public class GNUAPI {
|
|||
Account account = new Account();
|
||||
try {
|
||||
account.setId(resobj.get("id").toString());
|
||||
account.setUuid(resobj.get("ostatus_uri").toString());
|
||||
if( resobj.has("ostatus_uri"))
|
||||
account.setUuid(resobj.get("ostatus_uri").toString());
|
||||
else
|
||||
account.setUuid(resobj.get("id").toString());
|
||||
account.setUsername(resobj.get("name").toString());
|
||||
account.setAcct(resobj.get("name").toString());
|
||||
account.setDisplay_name(resobj.get("screen_name").toString());
|
||||
|
@ -1880,8 +1927,13 @@ public class GNUAPI {
|
|||
account.setUrl(resobj.get("url").toString());
|
||||
account.setAvatar(resobj.get("profile_image_url_https").toString());
|
||||
account.setAvatar_static(resobj.get("profile_image_url_https").toString());
|
||||
account.setHeader(resobj.get("background_image").toString());
|
||||
account.setHeader_static(resobj.get("background_image").toString());
|
||||
if( !resobj.isNull("background_image")) {
|
||||
account.setHeader(resobj.get("background_image").toString());
|
||||
account.setHeader_static(resobj.get("background_image").toString());
|
||||
}else{
|
||||
account.setHeader("null");
|
||||
account.setHeader_static("null");
|
||||
}
|
||||
account.setSocial("GNU");
|
||||
|
||||
account.setEmojis(new ArrayList<>());
|
||||
|
|
|
@ -13,6 +13,7 @@ package fr.gouv.etalab.mastodon.fragments;
|
|||
*
|
||||
* 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.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
@ -47,13 +48,14 @@ import static fr.gouv.etalab.mastodon.helper.Helper.THEME_LIGHT;
|
|||
public class TabLayoutNotificationsFragment extends Fragment {
|
||||
|
||||
private Context context;
|
||||
private ViewPager viewPager;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
||||
context = getContext();
|
||||
View inflatedView = inflater.inflate(R.layout.tablayout_settings, container, false);
|
||||
View inflatedView = inflater.inflate(R.layout.tablayout_notifications, container, false);
|
||||
|
||||
TabLayout tabLayout = inflatedView.findViewById(R.id.tabLayout);
|
||||
|
||||
|
@ -66,10 +68,14 @@ public class TabLayoutNotificationsFragment extends Fragment {
|
|||
TabLayout.Tab tabFollow = tabLayout.newTab();
|
||||
|
||||
tabMention.setCustomView(R.layout.tab_badge);
|
||||
tabFav.setCustomView(R.layout.tab_badge);
|
||||
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU)
|
||||
tabFav.setCustomView(R.layout.tab_badge);
|
||||
tabBoost.setCustomView(R.layout.tab_badge);
|
||||
tabFollow.setCustomView(R.layout.tab_badge);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||
|
||||
|
@ -78,18 +84,28 @@ public class TabLayoutNotificationsFragment extends Fragment {
|
|||
iconMention.setImageResource(R.drawable.ic_mention_notif_tab);
|
||||
|
||||
|
||||
@SuppressWarnings("ConstantConditions") @SuppressLint("CutPasteId")
|
||||
ImageView iconFav = tabMention.getCustomView().findViewById(R.id.tab_icon);
|
||||
iconFav.setImageResource(R.drawable.ic_star_notif_tab);
|
||||
ImageView iconFav =null;
|
||||
if( tabFav.getCustomView() != null) {
|
||||
iconFav = tabFav.getCustomView().findViewById(R.id.tab_icon);
|
||||
iconFav.setImageResource(R.drawable.ic_star_notif_tab);
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions") @SuppressLint("CutPasteId")
|
||||
ImageView iconBoost = tabMention.getCustomView().findViewById(R.id.tab_icon);
|
||||
ImageView iconBoost = tabBoost.getCustomView().findViewById(R.id.tab_icon);
|
||||
iconBoost.setImageResource(R.drawable.ic_repeat_notif_tab);
|
||||
|
||||
@SuppressWarnings("ConstantConditions") @SuppressLint("CutPasteId")
|
||||
ImageView iconFollow = tabMention.getCustomView().findViewById(R.id.tab_icon);
|
||||
ImageView iconFollow = tabFollow.getCustomView().findViewById(R.id.tab_icon);
|
||||
iconFollow.setImageResource(R.drawable.ic_follow_notif_tab);
|
||||
|
||||
|
||||
|
||||
tabLayout.addTab(tabMention);
|
||||
if( tabFav.getCustomView() != null)
|
||||
tabLayout.addTab(tabFav);
|
||||
tabLayout.addTab(tabBoost);
|
||||
tabLayout.addTab(tabFollow);
|
||||
|
||||
if (theme == THEME_BLACK)
|
||||
iconMention.setColorFilter(ContextCompat.getColor(context, R.color.dark_icon), PorterDuff.Mode.SRC_IN);
|
||||
else
|
||||
|
@ -97,18 +113,19 @@ public class TabLayoutNotificationsFragment extends Fragment {
|
|||
|
||||
if (theme == THEME_LIGHT) {
|
||||
iconMention.setColorFilter(ContextCompat.getColor(context, R.color.action_light_header), PorterDuff.Mode.SRC_IN);
|
||||
iconFav.setColorFilter(ContextCompat.getColor(context, R.color.action_light_header), PorterDuff.Mode.SRC_IN);
|
||||
if( iconFav != null)
|
||||
iconFav.setColorFilter(ContextCompat.getColor(context, R.color.action_light_header), PorterDuff.Mode.SRC_IN);
|
||||
iconBoost.setColorFilter(ContextCompat.getColor(context, R.color.action_light_header), PorterDuff.Mode.SRC_IN);
|
||||
iconFollow.setColorFilter(ContextCompat.getColor(context, R.color.action_light_header), PorterDuff.Mode.SRC_IN);
|
||||
} else {
|
||||
iconMention.setColorFilter(ContextCompat.getColor(context, R.color.dark_text), PorterDuff.Mode.SRC_IN);
|
||||
iconFav.setColorFilter(ContextCompat.getColor(context, R.color.dark_text), PorterDuff.Mode.SRC_IN);
|
||||
if( iconFav != null)
|
||||
iconFav.setColorFilter(ContextCompat.getColor(context, R.color.dark_text), PorterDuff.Mode.SRC_IN);
|
||||
iconBoost.setColorFilter(ContextCompat.getColor(context, R.color.dark_text), PorterDuff.Mode.SRC_IN);
|
||||
iconFollow.setColorFilter(ContextCompat.getColor(context, R.color.dark_text), PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
|
||||
|
||||
final ViewPager viewPager = inflatedView.findViewById(R.id.viewpager);
|
||||
viewPager = inflatedView.findViewById(R.id.viewpager);
|
||||
|
||||
viewPager.setAdapter(new PagerAdapter
|
||||
(getChildFragmentManager(), tabLayout.getTabCount()));
|
||||
|
@ -154,30 +171,28 @@ public class TabLayoutNotificationsFragment extends Fragment {
|
|||
public Fragment getItem(int position) {
|
||||
DisplayNotificationsFragment displayNotificationsFragment = new DisplayNotificationsFragment();
|
||||
DisplayNotificationsFragment.Type type = null;
|
||||
String tag = "";
|
||||
switch (position) {
|
||||
case 0:
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU )
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU ) {
|
||||
type = DisplayNotificationsFragment.Type.ALL;
|
||||
else
|
||||
}else
|
||||
type = DisplayNotificationsFragment.Type.MENTION;
|
||||
break;
|
||||
case 1:
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU )
|
||||
type = DisplayNotificationsFragment.Type.MENTION;
|
||||
else
|
||||
type = DisplayNotificationsFragment.Type.FAVORITE;
|
||||
type = DisplayNotificationsFragment.Type.BOOST;
|
||||
break;
|
||||
case 2:
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU )
|
||||
type = DisplayNotificationsFragment.Type.FAVORITE;
|
||||
else
|
||||
type = DisplayNotificationsFragment.Type.BOOST;
|
||||
type = DisplayNotificationsFragment.Type.FOLLOW;
|
||||
break;
|
||||
case 3:
|
||||
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU )
|
||||
type = DisplayNotificationsFragment.Type.BOOST;
|
||||
else
|
||||
type = DisplayNotificationsFragment.Type.FOLLOW;
|
||||
type = DisplayNotificationsFragment.Type.BOOST;
|
||||
break;
|
||||
case 4:
|
||||
type = DisplayNotificationsFragment.Type.FOLLOW;
|
||||
|
@ -192,9 +207,27 @@ public class TabLayoutNotificationsFragment extends Fragment {
|
|||
return displayNotificationsFragment;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mNumOfTabs;
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshAll(){
|
||||
|
||||
FragmentStatePagerAdapter a = (FragmentStatePagerAdapter) viewPager.getAdapter();
|
||||
if( a != null) {
|
||||
DisplayNotificationsFragment notifAll = (DisplayNotificationsFragment) a.instantiateItem(viewPager, 0);
|
||||
notifAll.refreshAll();
|
||||
}
|
||||
}
|
||||
|
||||
public void retrieveMissingNotifications(String sinceId){
|
||||
FragmentStatePagerAdapter a = (FragmentStatePagerAdapter) viewPager.getAdapter();
|
||||
if( a != null) {
|
||||
DisplayNotificationsFragment notifAll = (DisplayNotificationsFragment) a.instantiateItem(viewPager, 0);
|
||||
notifAll.retrieveMissingNotifications(sinceId);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
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>.
|
||||
-->
|
||||
<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:background="@null"
|
||||
android:orientation="vertical"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<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"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue