Merged in develop (pull request #8)
|
@ -7,8 +7,8 @@ android {
|
|||
applicationId "fr.gouv.etalab.mastodon"
|
||||
minSdkVersion 15
|
||||
targetSdkVersion 25
|
||||
versionCode 10
|
||||
versionName "1.1.3"
|
||||
versionCode 11
|
||||
versionName "1.1.4"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
|
|
|
@ -14,16 +14,20 @@
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
package fr.gouv.etalab.mastodon.activities;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Paint;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
@ -60,13 +64,17 @@ public class LoginActivity extends AppCompatActivity {
|
|||
private String client_secret;
|
||||
private TextView login_two_step;
|
||||
private static boolean client_id_for_webview = false;
|
||||
private String instance;
|
||||
private boolean addAccount = false;
|
||||
private EditText login_instance;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_login);
|
||||
|
||||
Button connectionButton = (Button) findViewById(R.id.login_button);
|
||||
final Button connectionButton = (Button) findViewById(R.id.login_button);
|
||||
login_instance = (EditText) findViewById(R.id.login_instance);
|
||||
connectionButton.setEnabled(false);
|
||||
login_two_step = (TextView) findViewById(R.id.login_two_step);
|
||||
login_two_step.setVisibility(View.GONE);
|
||||
|
@ -78,28 +86,61 @@ public class LoginActivity extends AppCompatActivity {
|
|||
retrievesClientId();
|
||||
}
|
||||
});
|
||||
|
||||
Bundle b = getIntent().getExtras();
|
||||
if(b != null)
|
||||
addAccount = b.getBoolean("addAccount", false);
|
||||
|
||||
if( addAccount )
|
||||
login_instance.setVisibility(View.VISIBLE);
|
||||
|
||||
if( addAccount) {
|
||||
login_instance.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||
@Override
|
||||
public void onFocusChange(View v, boolean hasFocus) {
|
||||
connectionButton.setEnabled(false);
|
||||
login_two_step.setVisibility(View.INVISIBLE);
|
||||
if (!hasFocus) {
|
||||
retrievesClientId();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume(){
|
||||
super.onResume();
|
||||
Button connectionButton = (Button) findViewById(R.id.login_button);
|
||||
if( client_id_for_webview || !connectionButton.isEnabled()) {
|
||||
connectionButton.setEnabled(false);
|
||||
client_id_for_webview = false;
|
||||
retrievesClientId();
|
||||
if( !addAccount ) {
|
||||
if (client_id_for_webview || !connectionButton.isEnabled()) {
|
||||
connectionButton.setEnabled(false);
|
||||
client_id_for_webview = false;
|
||||
retrievesClientId();
|
||||
}
|
||||
}else {
|
||||
if (login_instance.getText() != null && login_instance.getText().toString().length() > 0 && client_id_for_webview) {
|
||||
connectionButton.setEnabled(false);
|
||||
client_id_for_webview = false;
|
||||
retrievesClientId();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void retrievesClientId(){
|
||||
final Button connectionButton = (Button) findViewById(R.id.login_button);
|
||||
if( login_instance.getText() != null && login_instance.getText().length() > 0 )
|
||||
instance = login_instance.getText().toString().trim();
|
||||
else
|
||||
instance = Helper.INSTANCE;
|
||||
|
||||
String action = "/api/v1/apps";
|
||||
RequestParams parameters = new RequestParams();
|
||||
parameters.add(Helper.CLIENT_NAME, Helper.OAUTH_REDIRECT_HOST);
|
||||
parameters.add(Helper.REDIRECT_URIS, client_id_for_webview?Helper.REDIRECT_CONTENT_WEB:Helper.REDIRECT_CONTENT);
|
||||
parameters.add(Helper.SCOPES, Helper.OAUTH_SCOPES);
|
||||
parameters.add(Helper.WEBSITE,"https://" + Helper.INSTANCE);
|
||||
new OauthClient().post(action, parameters, new AsyncHttpResponseHandler() {
|
||||
parameters.add(Helper.WEBSITE,"https://" + Helper.getLiveInstance(getApplicationContext()));
|
||||
new OauthClient(instance).post(action, parameters, new AsyncHttpResponseHandler() {
|
||||
@Override
|
||||
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
|
||||
String response = new String(responseBody);
|
||||
|
@ -120,6 +161,7 @@ public class LoginActivity extends AppCompatActivity {
|
|||
login_two_step.setVisibility(View.VISIBLE);
|
||||
if( client_id_for_webview){
|
||||
Intent i = new Intent(LoginActivity.this, WebviewActivity.class);
|
||||
i.putExtra("instance", instance);
|
||||
startActivity(i);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
|
@ -158,7 +200,7 @@ public class LoginActivity extends AppCompatActivity {
|
|||
client.setUserAgent(USER_AGENT);
|
||||
try {
|
||||
client.setSSLSocketFactory(new MastalabSSLSocketFactory(MastalabSSLSocketFactory.getKeystore()));
|
||||
client.post("https://" + Helper.INSTANCE + "/oauth/token", requestParams, new AsyncHttpResponseHandler() {
|
||||
client.post("https://" + instance+ "/oauth/token", requestParams, new AsyncHttpResponseHandler() {
|
||||
@Override
|
||||
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
|
||||
String response = new String(responseBody);
|
||||
|
@ -171,7 +213,7 @@ public class LoginActivity extends AppCompatActivity {
|
|||
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token);
|
||||
editor.apply();
|
||||
//Update the account with the token;
|
||||
new UpdateAccountInfoAsyncTask(LoginActivity.this, token).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
new UpdateAccountInfoAsyncTask(LoginActivity.this, token, instance).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -180,6 +222,7 @@ public class LoginActivity extends AppCompatActivity {
|
|||
@Override
|
||||
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
|
||||
connectionButton.setEnabled(true);
|
||||
error.printStackTrace();
|
||||
Toast.makeText(getApplicationContext(),R.string.toast_error_login,Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
|
@ -192,4 +235,7 @@ public class LoginActivity extends AppCompatActivity {
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -35,10 +35,7 @@ import android.view.Menu;
|
|||
import android.view.MenuItem;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
|
||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
|
@ -67,6 +64,10 @@ import mastodon.etalab.gouv.fr.mastodon.R;
|
|||
import static fr.gouv.etalab.mastodon.helper.Helper.HOME_TIMELINE_INTENT;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.NOTIFICATION_INTENT;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.PREF_KEY_ID;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.changeUser;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.menuAccounts;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.updateHeaderAccountInfo;
|
||||
|
||||
public class MainActivity extends AppCompatActivity
|
||||
implements NavigationView.OnNavigationItemSelectedListener, OnUpdateAccountInfoInterface {
|
||||
|
@ -137,20 +138,18 @@ public class MainActivity extends AppCompatActivity
|
|||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
Account account = new AccountDAO(getApplicationContext(), db).getAccountByToken(prefKeyOauthTokenT);
|
||||
updateHeaderAccountInfo(account);
|
||||
boolean menuWasSelected = false;
|
||||
if( getIntent() != null && getIntent().getExtras() != null ){
|
||||
Bundle extras = getIntent().getExtras();
|
||||
if (extras.getInt(INTENT_ACTION) == NOTIFICATION_INTENT){
|
||||
navigationView.setCheckedItem(R.id.nav_notification);
|
||||
navigationView.getMenu().performIdentifierAction(R.id.nav_notification, 0);
|
||||
menuWasSelected = true;
|
||||
}else if( extras.getInt(INTENT_ACTION) == HOME_TIMELINE_INTENT){
|
||||
navigationView.setCheckedItem(R.id.nav_home);
|
||||
navigationView.getMenu().performIdentifierAction(R.id.nav_home, 0);
|
||||
menuWasSelected = true;
|
||||
updateHeaderAccountInfo(MainActivity.this, account, headerLayout, imageLoader, options);
|
||||
|
||||
LinearLayout owner_container = (LinearLayout) headerLayout.findViewById(R.id.owner_container);
|
||||
owner_container.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
menuAccounts(MainActivity.this);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
boolean menuWasSelected = false;
|
||||
mamageNewIntent(getIntent());
|
||||
if (savedInstanceState == null && !menuWasSelected) {
|
||||
navigationView.setCheckedItem(R.id.nav_home);
|
||||
navigationView.getMenu().performIdentifierAction(R.id.nav_home, 0);
|
||||
|
@ -193,15 +192,32 @@ public class MainActivity extends AppCompatActivity
|
|||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
mamageNewIntent(intent);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Manages new intents
|
||||
* @param intent Intent - intent related to a notification in top bar
|
||||
*/
|
||||
private void mamageNewIntent(Intent intent){
|
||||
if( intent == null || intent.getExtras() == null )
|
||||
return;
|
||||
Bundle extras = intent.getExtras();
|
||||
String userIdIntent;
|
||||
if( extras.containsKey(INTENT_ACTION) ){
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); //Id of the authenticated account
|
||||
final NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
|
||||
userIdIntent = extras.getString(PREF_KEY_ID); //Id of the account in the intent
|
||||
if (extras.getInt(INTENT_ACTION) == NOTIFICATION_INTENT){
|
||||
if( userId!= null && !userId.equals(userIdIntent)) //Connected account is different from the id in the intent
|
||||
changeUser(MainActivity.this, userIdIntent); //Connects the account which is related to the notification
|
||||
navigationView.setCheckedItem(R.id.nav_notification);
|
||||
navigationView.getMenu().performIdentifierAction(R.id.nav_notification, 0);
|
||||
}else if( extras.getInt(INTENT_ACTION) == HOME_TIMELINE_INTENT){
|
||||
if( userId!= null && !userId.equals(userIdIntent)) //Connected account is different from the id in the intent
|
||||
changeUser(MainActivity.this, userIdIntent); //Connects the account which is related to the notification
|
||||
navigationView.setCheckedItem(R.id.nav_home);
|
||||
navigationView.getMenu().performIdentifierAction(R.id.nav_home, 0);
|
||||
}
|
||||
|
@ -436,29 +452,6 @@ public class MainActivity extends AppCompatActivity
|
|||
return true;
|
||||
}
|
||||
|
||||
private void updateHeaderAccountInfo(Account account){
|
||||
ImageView profilePicture = (ImageView) headerLayout.findViewById(R.id.profilePicture);
|
||||
TextView username = (TextView) headerLayout.findViewById(R.id.username);
|
||||
TextView displayedName = (TextView) headerLayout.findViewById(R.id.displayedName);
|
||||
TextView ownerStatus = (TextView) headerLayout.findViewById(R.id.owner_status);
|
||||
TextView ownerFollowing = (TextView) headerLayout.findViewById(R.id.owner_following);
|
||||
TextView ownerFollowers = (TextView) headerLayout.findViewById(R.id.owner_followers);
|
||||
//Something wrong happened with the account recorded in db (ie: bad token)
|
||||
if( account == null ) {
|
||||
Helper.logout(getApplicationContext());
|
||||
Intent myIntent = new Intent(MainActivity.this, LoginActivity.class);
|
||||
Toast.makeText(getApplicationContext(),R.string.toast_error, Toast.LENGTH_LONG).show();
|
||||
startActivity(myIntent);
|
||||
finish(); //User is logged out to get a new token
|
||||
}else {
|
||||
ownerStatus.setText(String.valueOf(account.getStatuses_count()));
|
||||
ownerFollowers.setText(String.valueOf(account.getFollowers_count()));
|
||||
ownerFollowing.setText(String.valueOf(account.getFollowing_count()));
|
||||
username.setText(String.format("@%s",account.getUsername()));
|
||||
displayedName.setText(account.getDisplay_name());
|
||||
imageLoader.displayImage(account.getAvatar(), profilePicture, options);
|
||||
}
|
||||
}
|
||||
|
||||
private void populateTitleWithTag(String tag, String title, int index){
|
||||
if( tag == null)
|
||||
|
@ -488,7 +481,7 @@ public class MainActivity extends AppCompatActivity
|
|||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
SQLiteDatabase db = Sqlite.getInstance(MainActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(getApplicationContext(), db).getAccountByID(userId);
|
||||
updateHeaderAccountInfo(account);
|
||||
updateHeaderAccountInfo(MainActivity.this, account, headerLayout, imageLoader, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,11 +53,18 @@ public class WebviewActivity extends AppCompatActivity {
|
|||
private WebView webView;
|
||||
private AlertDialog alert;
|
||||
private String clientId, clientSecret;
|
||||
private String instance;
|
||||
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_webview);
|
||||
Bundle b = getIntent().getExtras();
|
||||
if(b != null)
|
||||
instance = b.getString("instance");
|
||||
if( instance == null)
|
||||
finish();
|
||||
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
clientId = sharedpreferences.getString(Helper.CLIENT_ID, null);
|
||||
clientSecret = sharedpreferences.getString(Helper.CLIENT_SECRET, null);
|
||||
|
@ -95,7 +102,7 @@ public class WebviewActivity extends AppCompatActivity {
|
|||
parameters.add(Helper.REDIRECT_URI,Helper.REDIRECT_CONTENT_WEB);
|
||||
parameters.add("grant_type", "authorization_code");
|
||||
parameters.add("code",code);
|
||||
new OauthClient().post(action, parameters, new AsyncHttpResponseHandler() {
|
||||
new OauthClient(instance).post(action, parameters, new AsyncHttpResponseHandler() {
|
||||
@Override
|
||||
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
|
||||
String response = new String(responseBody);
|
||||
|
@ -108,7 +115,7 @@ public class WebviewActivity extends AppCompatActivity {
|
|||
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token);
|
||||
editor.apply();
|
||||
//Update the account with the token;
|
||||
new UpdateAccountInfoAsyncTask(WebviewActivity.this, token).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
new UpdateAccountInfoAsyncTask(WebviewActivity.this, token, instance).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -149,7 +156,7 @@ public class WebviewActivity extends AppCompatActivity {
|
|||
queryString += "&" + Helper.REDIRECT_URI + "="+ Uri.encode(Helper.REDIRECT_CONTENT_WEB);
|
||||
queryString += "&" + Helper.RESPONSE_TYPE +"=code";
|
||||
queryString += "&" + Helper.SCOPE +"=" + Helper.OAUTH_SCOPES;
|
||||
return "https://" + Helper.INSTANCE + Helper.EP_AUTHORIZE + "?" + queryString;
|
||||
return "https://" + instance + Helper.EP_AUTHORIZE + "?" + queryString;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
/* Copyright 2017 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Mastodon Etalab for mastodon.etalab.gouv.fr
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Mastodon Etalab 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 Thomas Schneider; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
package fr.gouv.etalab.mastodon.asynctasks;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.AsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||
|
||||
/**
|
||||
* Created by Thomas on 28/05/2017.
|
||||
* Remove an account in db
|
||||
*/
|
||||
|
||||
public class RemoveAccountAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private Activity activity;
|
||||
private Account account;
|
||||
|
||||
public RemoveAccountAsyncTask(Activity activity, Account account){
|
||||
this.activity = activity;
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
SQLiteDatabase db = Sqlite.getInstance(activity, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
new AccountDAO(activity, db).removeUser(account);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -32,26 +32,30 @@ public class RetrieveHomeTimelineServiceAsyncTask extends AsyncTask<Void, Void,
|
|||
private Context context;
|
||||
private List<fr.gouv.etalab.mastodon.client.Entities.Status> statuses;
|
||||
private String since_id;
|
||||
private String acct;
|
||||
private String acct, userId;
|
||||
private OnRetrieveHomeTimelineServiceInterface listener;
|
||||
private String instance;
|
||||
private String token;
|
||||
|
||||
|
||||
public RetrieveHomeTimelineServiceAsyncTask(Context context, String since_id, String acct, OnRetrieveHomeTimelineServiceInterface onRetrieveHomeTimelineServiceInterface){
|
||||
public RetrieveHomeTimelineServiceAsyncTask(Context context, String instance, String token, String since_id, String acct, String userId, OnRetrieveHomeTimelineServiceInterface onRetrieveHomeTimelineServiceInterface){
|
||||
this.context = context;
|
||||
this.since_id = since_id;
|
||||
this.listener = onRetrieveHomeTimelineServiceInterface;
|
||||
this.acct = acct;
|
||||
this.instance = instance;
|
||||
this.userId = userId;
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
statuses = new API(context).getHomeTimelineSinceId(since_id);
|
||||
statuses = new API(context, instance, token).getHomeTimelineSinceId(since_id);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrieveHomeTimelineService(statuses, acct);
|
||||
listener.onRetrieveHomeTimelineService(statuses, acct, userId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import android.os.AsyncTask;
|
|||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveNotificationsInterface;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Notification;
|
||||
|
||||
|
@ -34,29 +35,35 @@ public class RetrieveNotificationsAsyncTask extends AsyncTask<Void, Void, Void>
|
|||
private Context context;
|
||||
private List<Notification> notifications;
|
||||
private String max_id;
|
||||
private String acct;
|
||||
private String acct, userId;
|
||||
private OnRetrieveNotificationsInterface listener;
|
||||
private String instance;
|
||||
private String token;
|
||||
|
||||
|
||||
public RetrieveNotificationsAsyncTask(Context context, String max_id, String acct, OnRetrieveNotificationsInterface onRetrieveNotificationsInterface){
|
||||
|
||||
public RetrieveNotificationsAsyncTask(Context context, String instance, String token, String max_id, String acct, String userId, OnRetrieveNotificationsInterface onRetrieveNotificationsInterface){
|
||||
this.context = context;
|
||||
this.max_id = max_id;
|
||||
this.listener = onRetrieveNotificationsInterface;
|
||||
this.acct = acct;
|
||||
this.instance = instance;
|
||||
this.userId = userId;
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
if( acct == null)
|
||||
notifications = new API(context).getNotifications(max_id);
|
||||
notifications = new API(context, instance, token).getNotifications(max_id);
|
||||
else
|
||||
notifications = new API(context).getNotificationsSince(max_id);
|
||||
notifications = new API(context, instance, token).getNotificationsSince(max_id);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrieveNotifications(notifications, acct);
|
||||
listener.onRetrieveNotifications(notifications, acct, userId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import android.content.Intent;
|
|||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
|
@ -37,23 +38,24 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
|
||||
private Context context;
|
||||
private String token;
|
||||
private String instance;
|
||||
|
||||
public UpdateAccountInfoAsyncTask(Context context, String token){
|
||||
public UpdateAccountInfoAsyncTask(Context context, String token, String instance){
|
||||
this.context = context;
|
||||
this.token = token;
|
||||
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
Account account = new API(context).verifyCredentials();
|
||||
Account account = new API(context, instance, null).verifyCredentials();
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
if( token == null) {
|
||||
token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
}
|
||||
account.setToken(token);
|
||||
//TODO: remove this static value to allow other instances
|
||||
account.setInstance(Helper.INSTANCE);
|
||||
account.setInstance(instance);
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
boolean userExists = new AccountDAO(context, db).userExist(account);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
|
|
|
@ -59,7 +59,7 @@ import static fr.gouv.etalab.mastodon.helper.Helper.USER_AGENT;
|
|||
public class API {
|
||||
|
||||
|
||||
private static final String BASE_URL = "https://" + Helper.INSTANCE + "/api/v1";
|
||||
|
||||
|
||||
private SyncHttpClient client = new SyncHttpClient();
|
||||
|
||||
|
@ -74,6 +74,8 @@ public class API {
|
|||
private List<Notification> notifications;
|
||||
private int tootPerPage, accountPerPage, notificationPerPage;
|
||||
private int actionCode;
|
||||
private String instance;
|
||||
private String prefKeyOauthTokenT;
|
||||
|
||||
public enum StatusAction{
|
||||
FAVOURITE,
|
||||
|
@ -97,8 +99,29 @@ public class API {
|
|||
tootPerPage = sharedpreferences.getInt(Helper.SET_TOOTS_PER_PAGE, 40);
|
||||
accountPerPage = sharedpreferences.getInt(Helper.SET_ACCOUNTS_PER_PAGE, 40);
|
||||
notificationPerPage = sharedpreferences.getInt(Helper.SET_NOTIFICATIONS_PER_PAGE, 40);
|
||||
this.instance = Helper.getLiveInstance(context);
|
||||
this.prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
}
|
||||
|
||||
public API(Context context, String instance, String token) {
|
||||
this.context = context;
|
||||
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);
|
||||
notificationPerPage = sharedpreferences.getInt(Helper.SET_NOTIFICATIONS_PER_PAGE, 40);
|
||||
if( instance != null)
|
||||
this.instance = instance;
|
||||
else
|
||||
this.instance = Helper.getLiveInstance(context);
|
||||
|
||||
if( token != null)
|
||||
this.prefKeyOauthTokenT = token;
|
||||
else
|
||||
this.prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* Verifiy credential of the authenticated user *synchronously*
|
||||
* @return Account
|
||||
|
@ -772,7 +795,7 @@ public class API {
|
|||
}
|
||||
@Override
|
||||
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
|
||||
|
||||
error.printStackTrace();
|
||||
}
|
||||
});
|
||||
return notifications;
|
||||
|
@ -1210,11 +1233,10 @@ public class API {
|
|||
try {
|
||||
client.setConnectTimeout(10000); //10s timeout
|
||||
client.setUserAgent(USER_AGENT);
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
client.addHeader("Authorization", "Bearer "+prefKeyOauthTokenT);
|
||||
client.setSSLSocketFactory(new MastalabSSLSocketFactory(MastalabSSLSocketFactory.getKeystore()));
|
||||
client.get(getAbsoluteUrl(action), params, responseHandler);
|
||||
|
||||
} catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException | UnrecoverableKeyException e) {
|
||||
Toast.makeText(context, R.string.toast_error,Toast.LENGTH_LONG).show();
|
||||
e.printStackTrace();
|
||||
|
@ -1226,8 +1248,6 @@ public class API {
|
|||
try {
|
||||
client.setConnectTimeout(10000); //10s timeout
|
||||
client.setUserAgent(USER_AGENT);
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
client.addHeader("Authorization", "Bearer "+prefKeyOauthTokenT);
|
||||
client.setSSLSocketFactory(new MastalabSSLSocketFactory(MastalabSSLSocketFactory.getKeystore()));
|
||||
client.post(getAbsoluteUrl(action), params, responseHandler);
|
||||
|
@ -1241,8 +1261,6 @@ public class API {
|
|||
try {
|
||||
client.setConnectTimeout(10000); //10s timeout
|
||||
client.setUserAgent(USER_AGENT);
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
client.addHeader("Authorization", "Bearer "+prefKeyOauthTokenT);
|
||||
client.setSSLSocketFactory(new MastalabSSLSocketFactory(MastalabSSLSocketFactory.getKeystore()));
|
||||
client.delete(getAbsoluteUrl(action), params, responseHandler);
|
||||
|
@ -1252,10 +1270,10 @@ public class API {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private String getAbsoluteUrl(String action) {
|
||||
return BASE_URL + action;
|
||||
return "https://" + this.instance + "/api/v1" + action;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -35,9 +35,13 @@ import static fr.gouv.etalab.mastodon.helper.Helper.USER_AGENT;
|
|||
|
||||
public class OauthClient {
|
||||
|
||||
private static final String BASE_URL = "https://" + Helper.INSTANCE;
|
||||
|
||||
private static AsyncHttpClient client = new AsyncHttpClient();
|
||||
private String instance;
|
||||
|
||||
|
||||
public OauthClient(String instance){
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public void get(String action, RequestParams params, AsyncHttpResponseHandler responseHandler) {
|
||||
try {
|
||||
|
@ -63,7 +67,7 @@ public class OauthClient {
|
|||
}
|
||||
|
||||
private String getAbsoluteUrl(String action) {
|
||||
return BASE_URL + action;
|
||||
return "https://" + instance + action;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
if(firstVisibleItem + visibleItemCount == totalItemCount ) {
|
||||
if(!flag_loading ) {
|
||||
flag_loading = true;
|
||||
asyncTask = new RetrieveNotificationsAsyncTask(context, max_id, null,DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
asyncTask = new RetrieveNotificationsAsyncTask(context, null, null, max_id, null, null,DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
nextElementLoader.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
|
@ -108,7 +108,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
notifications = new ArrayList<>();
|
||||
firstLoad = true;
|
||||
flag_loading = true;
|
||||
asyncTask = new RetrieveNotificationsAsyncTask(context, max_id, null,DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
asyncTask = new RetrieveNotificationsAsyncTask(context, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
});
|
||||
swipeRefreshLayout.setColorSchemeResources(R.color.colorAccent,
|
||||
|
@ -116,7 +116,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
R.color.colorPrimaryDark);
|
||||
|
||||
|
||||
asyncTask = new RetrieveNotificationsAsyncTask(context, max_id, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
asyncTask = new RetrieveNotificationsAsyncTask(context, null, null, max_id, null, null, DisplayNotificationsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
return rootView;
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
|
||||
|
||||
@Override
|
||||
public void onRetrieveNotifications(List<Notification> notifications, String acct) {
|
||||
public void onRetrieveNotifications(List<Notification> notifications, String acct, String userId) {
|
||||
|
||||
if( firstLoad && (notifications == null || notifications.size() == 0))
|
||||
textviewNoAction.setVisibility(View.VISIBLE);
|
||||
|
@ -170,13 +170,13 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
//Store last notification id to avoid to notify for those that have been already seen
|
||||
if( notifications != null && notifications.size() > 0) {
|
||||
final SharedPreferences sharedpreferences = getContext().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
//acct is null when used in Fragment, data need to be retrieved via shared preferences and db
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
//acct is null as userId when used in Fragment, data need to be retrieved via shared preferences and db
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account currentAccount = new AccountDAO(context, db).getAccountByID(userId);
|
||||
if( currentAccount != null){
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + currentAccount.getAcct(), notifications.get(0).getId());
|
||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + currentAccount.getId(), notifications.get(0).getId());
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -256,7 +256,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
Account currentAccount = new AccountDAO(context, db).getAccountByID(userId);
|
||||
if( currentAccount != null){
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + currentAccount.getAcct(), statuses.get(0).getId());
|
||||
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + currentAccount.getId(), statuses.get(0).getId());
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package fr.gouv.etalab.mastodon.helper;
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.DownloadManager;
|
||||
import android.app.PendingIntent;
|
||||
|
@ -25,30 +26,56 @@ import android.content.DialogInterface;
|
|||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.app.NotificationManagerCompat;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.loopj.android.http.BuildConfig;
|
||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.nostra13.universalimageloader.core.assist.FailReason;
|
||||
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
|
||||
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
|
||||
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.InetAddress;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import fr.gouv.etalab.mastodon.activities.LoginActivity;
|
||||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RemoveAccountAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||
import mastodon.etalab.gouv.fr.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
|
||||
|
@ -134,6 +161,9 @@ public class Helper {
|
|||
//User agent
|
||||
public static final String USER_AGENT = "Mastalab/"+ BuildConfig.VERSION_NAME + " Android/"+ Build.VERSION.RELEASE;
|
||||
|
||||
|
||||
public static boolean menuAccountsOpened = false;
|
||||
|
||||
/***
|
||||
* Check if the user is connected to Internet
|
||||
* @return boolean
|
||||
|
@ -384,19 +414,16 @@ public class Helper {
|
|||
/**
|
||||
* Sends notification with intent
|
||||
* @param context Context
|
||||
* @param intentAction int intent action
|
||||
* @param intent Intent associated to the notifcation
|
||||
* @param notificationId int id of the notification
|
||||
* @param icon Bitmap profile picture
|
||||
* @param title String title of the notification
|
||||
* @param message String message for the notification
|
||||
*/
|
||||
public static void notify_user(Context context, int intentAction, int notificationId, Bitmap icon, String title, String message ) {
|
||||
public static void notify_user(Context context, Intent intent, int notificationId, Bitmap icon, String title, String message ) {
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
// prepare intent which is triggered if the user click on the notification
|
||||
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
|
||||
final Intent intent = new Intent(context, MainActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK );
|
||||
intent.putExtra(INTENT_ACTION, intentAction);
|
||||
PendingIntent pIntent = PendingIntent.getActivity(context, notificationId, intent, PendingIntent.FLAG_ONE_SHOT);
|
||||
RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
||||
// build notification
|
||||
|
@ -417,10 +444,207 @@ public class Helper {
|
|||
notificationManager.notify(notificationId, notificationBuilder.build());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the instance of the authenticated user
|
||||
* @param context Context
|
||||
* @return String domain instance
|
||||
*/
|
||||
public static String getLiveInstance(Context context){
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
if( userId == null) //User not authenticated
|
||||
return Helper.INSTANCE;
|
||||
Account account = new AccountDAO(context, db).getAccountByID(userId);
|
||||
if( account != null){
|
||||
return account.getInstance().trim();
|
||||
} //User not in db
|
||||
else return Helper.INSTANCE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts dp to pixel
|
||||
* @param dp float - the value in dp to convert
|
||||
* @param context Context
|
||||
* @return float - the converted value in pixel
|
||||
*/
|
||||
public static float convertDpToPixel(float dp, Context context){
|
||||
Resources resources = context.getResources();
|
||||
DisplayMetrics metrics = resources.getDisplayMetrics();
|
||||
return dp * ((float)metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Toggle for the menu (ie: main menu or accounts menu)
|
||||
* @param activity Activity
|
||||
*/
|
||||
public static void menuAccounts(final Activity activity){
|
||||
|
||||
final NavigationView navigationView = (NavigationView) activity.findViewById(R.id.nav_view);
|
||||
SharedPreferences mSharedPreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String currrentUserId = mSharedPreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
final ImageView arrow = (ImageView) navigationView.getHeaderView(0).findViewById(R.id.owner_accounts);
|
||||
if( currrentUserId == null)
|
||||
return;
|
||||
|
||||
if( !menuAccountsOpened ){
|
||||
|
||||
arrow.setImageResource(R.drawable.ic_arrow_drop_up);
|
||||
|
||||
navigationView.getMenu().clear();
|
||||
navigationView.inflateMenu(R.menu.menu_accounts);
|
||||
|
||||
SQLiteDatabase db = Sqlite.getInstance(activity, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
|
||||
final List<Account> accounts = new AccountDAO(activity, db).getAllAccount();
|
||||
navigationView.setItemIconTintList(null);
|
||||
for(final Account account: accounts) {
|
||||
if( !currrentUserId.equals(account.getId()) ) {
|
||||
final MenuItem item = navigationView.getMenu().add("@" + account.getAcct() + "@" + account.getInstance());
|
||||
ImageLoader imageLoader;
|
||||
DisplayImageOptions options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false)
|
||||
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
|
||||
imageLoader = ImageLoader.getInstance();
|
||||
final ImageView imageView = new ImageView(activity);
|
||||
item.setIcon(R.drawable.ic_person);
|
||||
imageLoader.displayImage(account.getAvatar(), imageView, options, new ImageLoadingListener() {
|
||||
@Override
|
||||
public void onLoadingStarted(String s, View view) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingFailed(String s, View view, FailReason failReason) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingComplete(String s, View view, Bitmap bitmap) {
|
||||
item.setIcon(new BitmapDrawable(activity.getResources(), bitmap));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingCancelled(String s, View view) {
|
||||
}
|
||||
});
|
||||
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
if( ! activity.isFinishing() ) {
|
||||
menuAccountsOpened = false;
|
||||
String userId = account.getId();
|
||||
Toast.makeText(activity, activity.getString(R.string.toast_account_changed, "@" + account.getAcct() + "@" + account.getInstance()), Toast.LENGTH_LONG).show();
|
||||
changeUser(activity, userId);
|
||||
arrow.setImageResource(R.drawable.ic_arrow_drop_down);
|
||||
navigationView.getMenu().clear();
|
||||
navigationView.inflateMenu(R.menu.activity_main_drawer);
|
||||
navigationView.setCheckedItem(R.id.nav_home);
|
||||
navigationView.getMenu().performIdentifierAction(R.id.nav_home, 0);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
item.setActionView(R.layout.update_account);
|
||||
ImageView deleteButton = (ImageView) item.getActionView().findViewById(R.id.account_remove_button);
|
||||
deleteButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
new AlertDialog.Builder(activity)
|
||||
.setTitle(activity.getString(R.string.delete_account_title))
|
||||
.setMessage(activity.getString(R.string.delete_account_message, "@" + account.getAcct() + "@" + account.getInstance()))
|
||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
new RemoveAccountAsyncTask(activity, account).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
item.setVisible(false);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// do nothing
|
||||
}
|
||||
})
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.show();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
MenuItem addItem = navigationView.getMenu().add(R.string.add_account);
|
||||
addItem.setIcon(R.drawable.ic_person_add);
|
||||
addItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
Intent intent = new Intent(activity, LoginActivity.class);
|
||||
intent.putExtra("addAccount", true);
|
||||
activity.startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}else{
|
||||
arrow.setImageResource(R.drawable.ic_arrow_drop_down);
|
||||
navigationView.getMenu().clear();
|
||||
navigationView.inflateMenu(R.menu.activity_main_drawer);
|
||||
|
||||
}
|
||||
menuAccountsOpened = !menuAccountsOpened;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the user in shared preferences
|
||||
* @param activity Activity
|
||||
* @param userID String - the new user id
|
||||
*/
|
||||
public static void changeUser(Activity activity, String userID) {
|
||||
|
||||
SQLiteDatabase db = Sqlite.getInstance(activity, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(activity,db).getAccountByID(userID);
|
||||
|
||||
SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, account.getToken());
|
||||
editor.putString(Helper.PREF_KEY_ID, account.getId());
|
||||
editor.apply();
|
||||
ImageLoader imageLoader;
|
||||
DisplayImageOptions options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false)
|
||||
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
|
||||
imageLoader = ImageLoader.getInstance();
|
||||
NavigationView navigationView = (NavigationView) activity.findViewById(R.id.nav_view);
|
||||
updateHeaderAccountInfo(activity, account, navigationView, imageLoader, options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the header with the new selected account
|
||||
* @param activity Activity
|
||||
* @param account Account - new account in use
|
||||
* @param headerLayout View - the menu header
|
||||
* @param imageLoader ImageLoader - instance of ImageLoader
|
||||
* @param options DisplayImageOptions - current configuration of ImageLoader
|
||||
*/
|
||||
public static void updateHeaderAccountInfo(Activity activity, Account account, View headerLayout, ImageLoader imageLoader, DisplayImageOptions options){
|
||||
ImageView profilePicture = (ImageView) headerLayout.findViewById(R.id.profilePicture);
|
||||
TextView username = (TextView) headerLayout.findViewById(R.id.username);
|
||||
TextView displayedName = (TextView) headerLayout.findViewById(R.id.displayedName);
|
||||
TextView ownerStatus = (TextView) headerLayout.findViewById(R.id.owner_status);
|
||||
TextView ownerFollowing = (TextView) headerLayout.findViewById(R.id.owner_following);
|
||||
TextView ownerFollowers = (TextView) headerLayout.findViewById(R.id.owner_followers);
|
||||
if( account == null ) {
|
||||
Helper.logout(activity);
|
||||
Intent myIntent = new Intent(activity, LoginActivity.class);
|
||||
Toast.makeText(activity,R.string.toast_error, Toast.LENGTH_LONG).show();
|
||||
activity.startActivity(myIntent);
|
||||
activity.finish(); //User is logged out to get a new token
|
||||
}else {
|
||||
ownerStatus.setText(String.valueOf(account.getStatuses_count()));
|
||||
ownerFollowers.setText(String.valueOf(account.getFollowers_count()));
|
||||
ownerFollowing.setText(String.valueOf(account.getFollowing_count()));
|
||||
username.setText(String.format("@%s",account.getUsername()));
|
||||
displayedName.setText(account.getDisplay_name());
|
||||
imageLoader.displayImage(account.getAvatar(), profilePicture, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,5 +23,5 @@ import fr.gouv.etalab.mastodon.client.Entities.Status;
|
|||
* Interface when home timeline toots have been retrieved
|
||||
*/
|
||||
public interface OnRetrieveHomeTimelineServiceInterface {
|
||||
void onRetrieveHomeTimelineService(List<Status> statuses, String acct);
|
||||
void onRetrieveHomeTimelineService(List<Status> statuses, String acct, String userId);
|
||||
}
|
||||
|
|
|
@ -24,5 +24,5 @@ import fr.gouv.etalab.mastodon.client.Entities.Notification;
|
|||
* Interface when notifications have been retrieved
|
||||
*/
|
||||
public interface OnRetrieveNotificationsInterface {
|
||||
void onRetrieveNotifications(List<Notification> notifications, String acct);
|
||||
void onRetrieveNotifications(List<Notification> notifications, String acct, String userId);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ package fr.gouv.etalab.mastodon.jobs;
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.graphics.Bitmap;
|
||||
|
@ -34,6 +35,7 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveHomeTimelineServiceAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||
|
@ -45,6 +47,8 @@ import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
|||
import mastodon.etalab.gouv.fr.mastodon.R;
|
||||
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.HOME_TIMELINE_INTENT;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.PREF_KEY_ID;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.notify_user;
|
||||
|
||||
|
||||
|
@ -102,9 +106,9 @@ public class HomeTimelineSyncJob extends Job implements OnRetrieveHomeTimelineSe
|
|||
return;
|
||||
//Retrieve users in db that owner has.
|
||||
for (Account account: accounts) {
|
||||
String since_id = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + account.getAcct(), null);
|
||||
notificationId = (int) Math.round(Double.parseDouble(account.getId())/1000);
|
||||
new RetrieveHomeTimelineServiceAsyncTask(getContext(), since_id, account.getAcct(), HomeTimelineSyncJob.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
String since_id = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + account.getId(), null);
|
||||
notificationId = (int) Math.round(Double.parseDouble(account.getId())/100);
|
||||
new RetrieveHomeTimelineServiceAsyncTask(getContext(), account.getInstance(), account.getToken(), since_id, account.getAcct(), account.getId(), HomeTimelineSyncJob.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -112,51 +116,53 @@ public class HomeTimelineSyncJob extends Job implements OnRetrieveHomeTimelineSe
|
|||
|
||||
|
||||
@Override
|
||||
public void onRetrieveHomeTimelineService(List<Status> statuses, String acct) {
|
||||
public void onRetrieveHomeTimelineService(List<Status> statuses, String acct, String userId) {
|
||||
if( statuses == null || statuses.size() == 0)
|
||||
return;
|
||||
Bitmap icon_notification = null;
|
||||
final SharedPreferences sharedpreferences = getContext().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
|
||||
String max_id = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + acct, null);
|
||||
String max_id = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, null);
|
||||
//No previous notifications in cache, so no notification will be sent
|
||||
if( max_id != null ){
|
||||
String message;
|
||||
String title = null;
|
||||
for(Status status: statuses){
|
||||
//The notification associated to max_id is discarded as it is supposed to have already been sent
|
||||
//Also, if the toot comes from the owner, we will avoid to warn him/her...
|
||||
if( status.getId().equals(max_id) || status.getAccount().getAcct().trim().equals(acct.trim()))
|
||||
continue;
|
||||
String notificationUrl = status.getAccount().getAvatar();
|
||||
if( notificationUrl != null && icon_notification == null){
|
||||
try {
|
||||
ImageLoader imageLoaderNoty = ImageLoader.getInstance();
|
||||
File cacheDir = new File(getContext().getCacheDir(), getContext().getString(R.string.app_name));
|
||||
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getContext())
|
||||
.imageDownloader(new PatchBaseImageDownloader(getContext()))
|
||||
.threadPoolSize(5)
|
||||
.threadPriority(Thread.MIN_PRIORITY + 3)
|
||||
.denyCacheImageMultipleSizesInMemory()
|
||||
.diskCache(new UnlimitedDiskCache(cacheDir))
|
||||
.build();
|
||||
imageLoaderNoty.init(config);
|
||||
icon_notification = imageLoaderNoty.loadImageSync(notificationUrl);
|
||||
title = getContext().getResources().getString(R.string.notif_pouet, status.getAccount().getDisplay_name());
|
||||
}catch (Exception e){
|
||||
icon_notification = BitmapFactory.decodeResource(getContext().getResources(),
|
||||
R.drawable.mastodonlogo);
|
||||
}
|
||||
String message;
|
||||
String title = null;
|
||||
for(Status status: statuses){
|
||||
//The notification associated to max_id is discarded as it is supposed to have already been sent
|
||||
//Also, if the toot comes from the owner, we will avoid to warn him/her...
|
||||
if( (max_id != null && status.getId().equals(max_id)) || status.getAccount().getAcct().trim().equals(acct.trim()))
|
||||
continue;
|
||||
String notificationUrl = status.getAccount().getAvatar();
|
||||
if( notificationUrl != null && icon_notification == null){
|
||||
try {
|
||||
ImageLoader imageLoaderNoty = ImageLoader.getInstance();
|
||||
File cacheDir = new File(getContext().getCacheDir(), getContext().getString(R.string.app_name));
|
||||
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getContext())
|
||||
.imageDownloader(new PatchBaseImageDownloader(getContext()))
|
||||
.threadPoolSize(5)
|
||||
.threadPriority(Thread.MIN_PRIORITY + 3)
|
||||
.denyCacheImageMultipleSizesInMemory()
|
||||
.diskCache(new UnlimitedDiskCache(cacheDir))
|
||||
.build();
|
||||
imageLoaderNoty.init(config);
|
||||
icon_notification = imageLoaderNoty.loadImageSync(notificationUrl);
|
||||
title = getContext().getResources().getString(R.string.notif_pouet, status.getAccount().getUsername());
|
||||
}catch (Exception e){
|
||||
icon_notification = BitmapFactory.decodeResource(getContext().getResources(),
|
||||
R.drawable.mastodonlogo);
|
||||
}
|
||||
}
|
||||
if(statuses.size() > 0 )
|
||||
message = getContext().getResources().getQuantityString(R.plurals.other_notif_hometimeline, statuses.size(), statuses.size());
|
||||
else
|
||||
message = "";
|
||||
notify_user(getContext(), HOME_TIMELINE_INTENT, notificationId, icon_notification,title,message);
|
||||
}
|
||||
if(statuses.size() > 0 )
|
||||
message = getContext().getResources().getQuantityString(R.plurals.other_notif_hometimeline, statuses.size(), statuses.size());
|
||||
else
|
||||
message = "";
|
||||
final Intent intent = new Intent(getContext(), MainActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK );
|
||||
intent.putExtra(INTENT_ACTION, HOME_TIMELINE_INTENT);
|
||||
intent.putExtra(PREF_KEY_ID, userId);
|
||||
notify_user(getContext(), intent, notificationId, icon_notification,title,message);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + acct, statuses.get(0).getId());
|
||||
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, statuses.get(0).getId());
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
|
|
|
@ -15,12 +15,14 @@ package fr.gouv.etalab.mastodon.jobs;
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.AsyncTask;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
import com.evernote.android.job.Job;
|
||||
|
@ -36,6 +38,7 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||
import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import mastodon.etalab.gouv.fr.mastodon.R;
|
||||
|
@ -46,7 +49,9 @@ import fr.gouv.etalab.mastodon.interfaces.OnRetrieveNotificationsInterface;
|
|||
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.NOTIFICATION_INTENT;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.PREF_KEY_ID;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.notify_user;
|
||||
|
||||
|
||||
|
@ -112,9 +117,9 @@ public class NotificationsSyncJob extends Job implements OnRetrieveNotifications
|
|||
return;
|
||||
//Retrieve users in db that owner has.
|
||||
for (Account account: accounts) {
|
||||
String max_id = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getAcct(), null);
|
||||
notificationId = (int) Math.round(Double.parseDouble(account.getId())/1000);
|
||||
new RetrieveNotificationsAsyncTask(getContext(), max_id, account.getAcct(), NotificationsSyncJob.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
String max_id = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId(), null);
|
||||
notificationId = (int) Math.round(Double.parseDouble(account.getId())/100);
|
||||
new RetrieveNotificationsAsyncTask(getContext(), account.getInstance(), account.getToken(), max_id, account.getAcct(), account.getId(), NotificationsSyncJob.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -122,102 +127,104 @@ public class NotificationsSyncJob extends Job implements OnRetrieveNotifications
|
|||
|
||||
|
||||
@Override
|
||||
public void onRetrieveNotifications(List<Notification> notifications, String acct) {
|
||||
public void onRetrieveNotifications(List<Notification> notifications, String acct, String userId) {
|
||||
if( notifications == null || notifications.size() == 0)
|
||||
return;
|
||||
Bitmap icon_notification = null;
|
||||
final SharedPreferences sharedpreferences = getContext().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean notif_follow = sharedpreferences.getBoolean(Helper.SET_NOTIF_FOLLOW, true);
|
||||
boolean notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD, true);
|
||||
//boolean notif_ask = sharedpreferences.getBoolean(Helper.SET_NOTIF_ASK, true);
|
||||
boolean notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true);
|
||||
boolean notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true);
|
||||
String max_id = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + acct, null);
|
||||
String max_id = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + userId, null);
|
||||
//No previous notifications in cache, so no notification will be sent
|
||||
if( max_id != null ){
|
||||
int newFollows = 0;
|
||||
int newAdds = 0;
|
||||
int newAsks = 0;
|
||||
int newMentions = 0;
|
||||
int newShare = 0;
|
||||
String notificationUrl = null;
|
||||
String title = null;
|
||||
String message;
|
||||
for(Notification notification: notifications){
|
||||
//The notification associated to max_id is discarded as it is supposed to have already been sent
|
||||
if( notification.getId().equals(max_id))
|
||||
continue;
|
||||
switch (notification.getType()){
|
||||
case "mention":
|
||||
if(notif_mention){
|
||||
newMentions++;
|
||||
if( notificationUrl == null){
|
||||
notificationUrl = notification.getAccount().getAvatar();
|
||||
title = String.format("@%s %s", notification.getAccount().getAcct(),getContext().getString(R.string.notif_mention));
|
||||
}
|
||||
int newFollows = 0;
|
||||
int newAdds = 0;
|
||||
int newAsks = 0;
|
||||
int newMentions = 0;
|
||||
int newShare = 0;
|
||||
String notificationUrl = null;
|
||||
String title = null;
|
||||
String message;
|
||||
for(Notification notification: notifications){
|
||||
//The notification associated to max_id is discarded as it is supposed to have already been sent
|
||||
if( max_id != null && notification.getId().equals(max_id))
|
||||
continue;
|
||||
switch (notification.getType()){
|
||||
case "mention":
|
||||
if(notif_mention){
|
||||
newMentions++;
|
||||
if( notificationUrl == null){
|
||||
notificationUrl = notification.getAccount().getAvatar();
|
||||
title = String.format("@%s %s", notification.getAccount().getUsername(),getContext().getString(R.string.notif_mention));
|
||||
}
|
||||
break;
|
||||
case "reblog":
|
||||
if(notif_share){
|
||||
newShare++;
|
||||
if( notificationUrl == null){
|
||||
notificationUrl = notification.getAccount().getAvatar();
|
||||
title = String.format("@%s %s", notification.getAccount().getAcct(),getContext().getString(R.string.notif_reblog));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "favourite":
|
||||
if(notif_add){
|
||||
newAdds++;
|
||||
if( notificationUrl == null){
|
||||
notificationUrl = notification.getAccount().getAvatar();
|
||||
title = String.format("@%s %s", notification.getAccount().getAcct(),getContext().getString(R.string.notif_favourite));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "follow":
|
||||
if(notif_follow){
|
||||
newFollows++;
|
||||
if( notificationUrl == null){
|
||||
notificationUrl = notification.getAccount().getAvatar();
|
||||
title = String.format("@%s %s", notification.getAccount().getAcct(),getContext().getString(R.string.notif_follow));
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
if( notificationUrl != null && icon_notification == null){
|
||||
try {
|
||||
ImageLoader imageLoaderNoty = ImageLoader.getInstance();
|
||||
File cacheDir = new File(getContext().getCacheDir(), getContext().getString(R.string.app_name));
|
||||
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getContext())
|
||||
.imageDownloader(new PatchBaseImageDownloader(getContext()))
|
||||
.threadPoolSize(5)
|
||||
.threadPriority(Thread.MIN_PRIORITY + 3)
|
||||
.denyCacheImageMultipleSizesInMemory()
|
||||
.diskCache(new UnlimitedDiskCache(cacheDir))
|
||||
.build();
|
||||
imageLoaderNoty.init(config);
|
||||
icon_notification = imageLoaderNoty.loadImageSync(notificationUrl);
|
||||
}catch (Exception e){
|
||||
icon_notification = BitmapFactory.decodeResource(getContext().getResources(),
|
||||
R.drawable.mastodonlogo);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "reblog":
|
||||
if(notif_share){
|
||||
newShare++;
|
||||
if( notificationUrl == null){
|
||||
notificationUrl = notification.getAccount().getAvatar();
|
||||
title = String.format("@%s %s", notification.getAccount().getUsername(),getContext().getString(R.string.notif_reblog));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "favourite":
|
||||
if(notif_add){
|
||||
newAdds++;
|
||||
if( notificationUrl == null){
|
||||
notificationUrl = notification.getAccount().getAvatar();
|
||||
title = String.format("@%s %s", notification.getAccount().getUsername(),getContext().getString(R.string.notif_favourite));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "follow":
|
||||
if(notif_follow){
|
||||
newFollows++;
|
||||
if( notificationUrl == null){
|
||||
notificationUrl = notification.getAccount().getAvatar();
|
||||
title = String.format("@%s %s", notification.getAccount().getUsername(),getContext().getString(R.string.notif_follow));
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
int allNotifCount = newFollows + newAdds + newAsks + newMentions + newShare;
|
||||
if( allNotifCount > 0){
|
||||
//Some others notification
|
||||
int other = allNotifCount -1;
|
||||
if(other > 0 )
|
||||
message = getContext().getResources().getQuantityString(R.plurals.other_notifications, other, other);
|
||||
else
|
||||
message = "";
|
||||
notify_user(getContext(), NOTIFICATION_INTENT, notificationId, icon_notification,title,message);
|
||||
if( notificationUrl != null && icon_notification == null){
|
||||
try {
|
||||
ImageLoader imageLoaderNoty = ImageLoader.getInstance();
|
||||
File cacheDir = new File(getContext().getCacheDir(), getContext().getString(R.string.app_name));
|
||||
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getContext())
|
||||
.imageDownloader(new PatchBaseImageDownloader(getContext()))
|
||||
.threadPoolSize(5)
|
||||
.threadPriority(Thread.MIN_PRIORITY + 3)
|
||||
.denyCacheImageMultipleSizesInMemory()
|
||||
.diskCache(new UnlimitedDiskCache(cacheDir))
|
||||
.build();
|
||||
imageLoaderNoty.init(config);
|
||||
icon_notification = imageLoaderNoty.loadImageSync(notificationUrl);
|
||||
}catch (Exception e){
|
||||
icon_notification = BitmapFactory.decodeResource(getContext().getResources(),
|
||||
R.drawable.mastodonlogo);
|
||||
}
|
||||
}
|
||||
}
|
||||
int allNotifCount = newFollows + newAdds + newAsks + newMentions + newShare;
|
||||
if( allNotifCount > 0){
|
||||
//Some others notification
|
||||
int other = allNotifCount -1;
|
||||
if(other > 0 )
|
||||
message = getContext().getResources().getQuantityString(R.plurals.other_notifications, other, other);
|
||||
else
|
||||
message = "";
|
||||
final Intent intent = new Intent(getContext(), MainActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK );
|
||||
intent.putExtra(INTENT_ACTION, NOTIFICATION_INTENT);
|
||||
intent.putExtra(PREF_KEY_ID, userId);
|
||||
notify_user(getContext(), intent, notificationId, icon_notification,title,message);
|
||||
}
|
||||
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + acct, notifications.get(0).getId());
|
||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId, notifications.get(0).getId());
|
||||
editor.apply();
|
||||
|
||||
}
|
||||
|
|
After Width: | Height: | Size: 125 B |
After Width: | Height: | Size: 130 B |
After Width: | Height: | Size: 435 B |
After Width: | Height: | Size: 291 B |
After Width: | Height: | Size: 313 B |
After Width: | Height: | Size: 172 B |
After Width: | Height: | Size: 165 B |
After Width: | Height: | Size: 309 B |
After Width: | Height: | Size: 258 B |
After Width: | Height: | Size: 289 B |
After Width: | Height: | Size: 95 B |
After Width: | Height: | Size: 98 B |
After Width: | Height: | Size: 312 B |
After Width: | Height: | Size: 199 B |
After Width: | Height: | Size: 211 B |
After Width: | Height: | Size: 120 B |
After Width: | Height: | Size: 130 B |
After Width: | Height: | Size: 572 B |
After Width: | Height: | Size: 330 B |
After Width: | Height: | Size: 356 B |
After Width: | Height: | Size: 152 B |
After Width: | Height: | Size: 159 B |
After Width: | Height: | Size: 813 B |
After Width: | Height: | Size: 481 B |
After Width: | Height: | Size: 515 B |
After Width: | Height: | Size: 185 B |
After Width: | Height: | Size: 991 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 651 B |
After Width: | Height: | Size: 688 B |
|
@ -37,6 +37,17 @@
|
|||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
|
||||
<EditText
|
||||
android:visibility="gone"
|
||||
android:id="@+id/login_instance"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textWebEmailAddress"
|
||||
android:hint="@string/instance"
|
||||
/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/login_uid"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -42,15 +42,30 @@
|
|||
<LinearLayout
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/owner_container"
|
||||
android:orientation="vertical">
|
||||
<TextView
|
||||
android:id="@+id/displayedName"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="18sp"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:id="@+id/displayedName"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="18sp"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
|
||||
<ImageView
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginStart="5dp"
|
||||
android:id="@+id/owner_accounts"
|
||||
android:layout_width="30dp"
|
||||
android:src="@drawable/ic_arrow_drop_down"
|
||||
android:layout_height="30dp"
|
||||
tools:ignore="ContentDescription" />
|
||||
</LinearLayout>
|
||||
<TextView
|
||||
android:id="@+id/username"
|
||||
android:layout_width="wrap_content"
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2017 Thomas Schneider
|
||||
|
||||
This file is a part of Mastodon Etalab for mastodon.etalab.gouv.fr
|
||||
|
||||
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.
|
||||
|
||||
Mastodon Etalab 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 Thomas Schneider; if not,
|
||||
see <http://www.gnu.org/licenses>.
|
||||
-->
|
||||
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="wrap_content"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_gravity="center_vertical">
|
||||
<ImageView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:layout_marginRight="5dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginStart="5dp"
|
||||
android:padding="5dp"
|
||||
android:id="@+id/account_remove_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:scaleType="center"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_cancel"
|
||||
tools:ignore="ContentDescription" />
|
||||
</LinearLayout>
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<group android:checkableBehavior="single">
|
||||
|
||||
</group>
|
||||
|
||||
</menu>
|
|
@ -24,6 +24,9 @@
|
|||
<string name="token">Jeton</string>
|
||||
<string name="two_factor_authentification">Authentification en deux étapes ?</string>
|
||||
<string name="no_result">Aucun résultat !</string>
|
||||
<string name="instance">Instance</string>
|
||||
<string name="toast_account_changed">Utilisation du compte %1$s</string>
|
||||
<string name="add_account">Ajouter un compte</string>
|
||||
<!--- Menu -->
|
||||
<string name="home_menu">Accueil</string>
|
||||
<string name="home_timeline">Accueil</string>
|
||||
|
@ -39,6 +42,8 @@
|
|||
<string name="notifications">Notifications</string>
|
||||
<string name="optimization">Optimisation</string>
|
||||
<string name="make_a_choice">Que souhaitez-vous faire ?</string>
|
||||
<string name="delete_account_title">Supprimer un compte</string>
|
||||
<string name="delete_account_message">Supprimer le compte %1$s de l\'application ?</string>
|
||||
|
||||
<!-- Status -->
|
||||
<string name="no_status">Aucun pouet à afficher !</string>
|
||||
|
|