2020-06-28 19:11:39 +02:00
|
|
|
package app.fedilab.fedilabtube;
|
2020-07-01 16:36:08 +02:00
|
|
|
/* Copyright 2020 Thomas Schneider
|
|
|
|
*
|
|
|
|
* This file is a part of TubeLab
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* TubeLab 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 TubeLab; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
2020-07-01 15:08:42 +02:00
|
|
|
|
2020-06-28 19:11:39 +02:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
2020-06-30 11:38:06 +02:00
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
2020-06-28 19:11:39 +02:00
|
|
|
import android.os.AsyncTask;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.text.SpannableString;
|
|
|
|
import android.text.Spanned;
|
|
|
|
import android.text.style.ForegroundColorSpan;
|
|
|
|
import android.text.style.UnderlineSpan;
|
|
|
|
import android.view.MenuItem;
|
2020-06-30 11:38:06 +02:00
|
|
|
import android.view.View;
|
2020-06-28 19:11:39 +02:00
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.EditText;
|
2020-06-30 11:38:06 +02:00
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
2020-07-01 15:08:42 +02:00
|
|
|
import android.widget.RelativeLayout;
|
2020-06-28 19:11:39 +02:00
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
2020-06-30 11:38:06 +02:00
|
|
|
import androidx.appcompat.app.AlertDialog;
|
2020-06-28 19:11:39 +02:00
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import androidx.core.content.ContextCompat;
|
2020-07-01 15:08:42 +02:00
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
2020-06-28 19:11:39 +02:00
|
|
|
|
2020-07-01 15:08:42 +02:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
2020-06-28 19:11:39 +02:00
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import java.net.URLEncoder;
|
2020-07-01 15:08:42 +02:00
|
|
|
import java.util.ArrayList;
|
2020-06-29 16:43:20 +02:00
|
|
|
import java.util.Arrays;
|
2020-06-28 19:11:39 +02:00
|
|
|
import java.util.HashMap;
|
2020-07-01 15:08:42 +02:00
|
|
|
import java.util.List;
|
2020-06-28 19:11:39 +02:00
|
|
|
|
2020-07-01 15:08:42 +02:00
|
|
|
import app.fedilab.fedilabtube.asynctasks.RetrievePeertubeNotificationsAsyncTask;
|
2020-06-28 19:11:39 +02:00
|
|
|
import app.fedilab.fedilabtube.asynctasks.UpdateAccountInfoAsyncTask;
|
2020-07-01 15:08:42 +02:00
|
|
|
import app.fedilab.fedilabtube.client.APIResponse;
|
2020-06-28 19:11:39 +02:00
|
|
|
import app.fedilab.fedilabtube.client.HttpsConnection;
|
2020-06-30 11:38:06 +02:00
|
|
|
import app.fedilab.fedilabtube.client.entities.Account;
|
2020-07-01 15:08:42 +02:00
|
|
|
import app.fedilab.fedilabtube.client.entities.PeertubeNotification;
|
|
|
|
import app.fedilab.fedilabtube.drawer.PeertubeNotificationsListAdapter;
|
2020-06-28 19:11:39 +02:00
|
|
|
import app.fedilab.fedilabtube.helper.Helper;
|
2020-07-01 15:08:42 +02:00
|
|
|
import app.fedilab.fedilabtube.interfaces.OnRetrievePeertubeNotificationsInterface;
|
2020-06-30 11:38:06 +02:00
|
|
|
import app.fedilab.fedilabtube.sqlite.AccountDAO;
|
|
|
|
import app.fedilab.fedilabtube.sqlite.Sqlite;
|
2020-06-28 19:11:39 +02:00
|
|
|
import es.dmoral.toasty.Toasty;
|
|
|
|
|
|
|
|
|
2020-07-01 15:08:42 +02:00
|
|
|
public class LoginActivity extends AppCompatActivity implements OnRetrievePeertubeNotificationsInterface {
|
2020-06-28 19:11:39 +02:00
|
|
|
|
|
|
|
|
2020-07-01 15:08:42 +02:00
|
|
|
//Peertube notification type
|
|
|
|
public static int NEW_VIDEO_FROM_SUBSCRIPTION = 1;
|
|
|
|
// public static int NEW_COMMENT_ON_MY_VIDEO = 2;
|
|
|
|
// public static int NEW_VIDEO_ABUSE_FOR_MODERATORS = 3;
|
|
|
|
public static int BLACKLIST_ON_MY_VIDEO = 4;
|
|
|
|
public static int UNBLACKLIST_ON_MY_VIDEO = 5;
|
|
|
|
public static int MY_VIDEO_PUBLISHED = 6;
|
|
|
|
public static int MY_VIDEO_IMPORT_SUCCESS = 7;
|
|
|
|
public static int MY_VIDEO_IMPORT_ERROR = 8;
|
2020-06-28 19:11:39 +02:00
|
|
|
private static String client_id;
|
|
|
|
private static String client_secret;
|
2020-07-01 15:08:42 +02:00
|
|
|
// public static int NEW_USER_REGISTRATION = 9;
|
|
|
|
//public static int NEW_FOLLOW = 10;
|
|
|
|
// public static int COMMENT_MENTION = 11;
|
|
|
|
LinearLayoutManager mLayoutManager;
|
2020-06-28 19:11:39 +02:00
|
|
|
private EditText login_uid;
|
|
|
|
private EditText login_passwd;
|
|
|
|
private Button connectionButton;
|
|
|
|
private String actionToken;
|
2020-07-01 15:08:42 +02:00
|
|
|
private boolean flag_loading;
|
|
|
|
private PeertubeNotificationsListAdapter notificationsListAdapter;
|
|
|
|
private String max_id;
|
|
|
|
private List<PeertubeNotification> notifications;
|
|
|
|
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
|
|
|
|
private boolean firstLoad;
|
|
|
|
private SwipeRefreshLayout swipeRefreshLayout;
|
|
|
|
private boolean swiped;
|
|
|
|
private AsyncTask<Void, Void, Void> asyncTask;
|
2020-06-28 19:11:39 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
|
|
|
|
setContentView(R.layout.activity_login);
|
|
|
|
if (getSupportActionBar() != null)
|
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
|
|
|
|
TextView create_an_account_peertube = findViewById(R.id.create_an_account_peertube);
|
|
|
|
|
2020-06-29 15:43:35 +02:00
|
|
|
|
2020-06-29 16:43:20 +02:00
|
|
|
SpannableString content_create = new SpannableString(getString(R.string.join_peertube));
|
|
|
|
content_create.setSpan(new UnderlineSpan(), 0, content_create.length(), 0);
|
|
|
|
content_create.setSpan(new ForegroundColorSpan(ContextCompat.getColor(LoginActivity.this, R.color.colorAccent)), 0, content_create.length(),
|
|
|
|
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
|
|
|
create_an_account_peertube.setText(content_create);
|
2020-06-28 19:11:39 +02:00
|
|
|
|
|
|
|
create_an_account_peertube.setOnClickListener(v -> {
|
|
|
|
Intent mainActivity = new Intent(LoginActivity.this, PeertubeRegisterActivity.class);
|
|
|
|
Bundle b = new Bundle();
|
|
|
|
mainActivity.putExtras(b);
|
|
|
|
startActivity(mainActivity);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
login_uid = findViewById(R.id.login_uid);
|
|
|
|
login_passwd = findViewById(R.id.login_passwd);
|
|
|
|
connectionButton = findViewById(R.id.login_button);
|
|
|
|
|
2020-06-30 11:38:06 +02:00
|
|
|
LinearLayout connected = findViewById(R.id.connected);
|
|
|
|
LinearLayout not_connected = findViewById(R.id.not_connected);
|
|
|
|
|
2020-06-30 13:33:43 +02:00
|
|
|
if (Helper.isLoggedIn(LoginActivity.this)) {
|
2020-06-30 11:38:06 +02:00
|
|
|
not_connected.setVisibility(View.GONE);
|
2020-07-01 15:19:24 +02:00
|
|
|
connected.setVisibility(View.VISIBLE);
|
2020-06-30 11:38:06 +02:00
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
|
|
|
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
|
|
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
|
|
|
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(LoginActivity.this));
|
|
|
|
|
|
|
|
TextView instanceView = findViewById(R.id.instance);
|
|
|
|
Account account = new AccountDAO(LoginActivity.this, db).getUniqAccount(userId, instance);
|
2020-06-30 13:33:43 +02:00
|
|
|
if (account == null) {
|
2020-06-30 11:38:06 +02:00
|
|
|
account = new AccountDAO(LoginActivity.this, db).getUniqAccount(userId, Helper.getPeertubeUrl(instance));
|
|
|
|
}
|
2020-06-30 13:33:43 +02:00
|
|
|
if (account != null) {
|
2020-06-30 11:38:06 +02:00
|
|
|
ImageView profile_picture = findViewById(R.id.profile_picture);
|
|
|
|
TextView username = findViewById(R.id.username);
|
|
|
|
TextView displayname = findViewById(R.id.displayname);
|
|
|
|
|
|
|
|
Helper.loadGiF(LoginActivity.this, account, profile_picture);
|
|
|
|
username.setText(String.format("@%s", account.getUsername()));
|
|
|
|
displayname.setText(account.getDisplay_name());
|
|
|
|
|
|
|
|
instanceView.setText(account.getInstance());
|
|
|
|
|
|
|
|
Button logout_button = findViewById(R.id.logout_button);
|
|
|
|
Account finalAccount = account;
|
|
|
|
logout_button.setOnClickListener(v -> {
|
|
|
|
AlertDialog.Builder dialogBuilderLogoutAccount = new AlertDialog.Builder(LoginActivity.this);
|
|
|
|
dialogBuilderLogoutAccount.setMessage(getString(R.string.logout_account_confirmation, finalAccount.getUsername()));
|
|
|
|
dialogBuilderLogoutAccount.setPositiveButton(R.string.action_logout, (dialog, id) -> {
|
|
|
|
Helper.logoutCurrentUser(LoginActivity.this, finalAccount);
|
|
|
|
dialog.dismiss();
|
|
|
|
});
|
|
|
|
dialogBuilderLogoutAccount.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
|
|
|
|
AlertDialog alertDialogLogoutAccount = dialogBuilderLogoutAccount.create();
|
|
|
|
alertDialogLogoutAccount.show();
|
|
|
|
});
|
2020-06-30 13:33:43 +02:00
|
|
|
} else {
|
2020-06-30 11:38:06 +02:00
|
|
|
Helper.logoutCurrentUser(LoginActivity.this, null);
|
|
|
|
}
|
|
|
|
|
2020-07-01 15:08:42 +02:00
|
|
|
max_id = null;
|
|
|
|
firstLoad = true;
|
|
|
|
flag_loading = true;
|
|
|
|
notifications = new ArrayList<>();
|
|
|
|
swiped = false;
|
|
|
|
swipeRefreshLayout = findViewById(R.id.swipeContainer);
|
|
|
|
|
|
|
|
RecyclerView lv_notifications = findViewById(R.id.lv_notifications);
|
|
|
|
mainLoader = findViewById(R.id.loader);
|
|
|
|
nextElementLoader = findViewById(R.id.loading_next_notifications);
|
|
|
|
textviewNoAction = findViewById(R.id.no_action);
|
|
|
|
mainLoader.setVisibility(View.VISIBLE);
|
|
|
|
nextElementLoader.setVisibility(View.GONE);
|
|
|
|
notificationsListAdapter = new PeertubeNotificationsListAdapter(this.notifications);
|
|
|
|
lv_notifications.setAdapter(notificationsListAdapter);
|
|
|
|
mLayoutManager = new LinearLayoutManager(LoginActivity.this);
|
|
|
|
lv_notifications.setLayoutManager(mLayoutManager);
|
|
|
|
lv_notifications.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
|
|
|
public void onScrolled(@NotNull RecyclerView recyclerView, int dx, int dy) {
|
|
|
|
if (dy > 0) {
|
|
|
|
int visibleItemCount = mLayoutManager.getChildCount();
|
|
|
|
int totalItemCount = mLayoutManager.getItemCount();
|
|
|
|
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
|
|
|
|
if (firstVisibleItem + visibleItemCount == totalItemCount) {
|
|
|
|
if (!flag_loading) {
|
|
|
|
flag_loading = true;
|
|
|
|
asyncTask = new RetrievePeertubeNotificationsAsyncTask(LoginActivity.this, null, max_id, LoginActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
|
nextElementLoader.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nextElementLoader.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-06-30 11:38:06 +02:00
|
|
|
|
2020-07-01 15:08:42 +02:00
|
|
|
swipeRefreshLayout.setOnRefreshListener(() -> {
|
|
|
|
max_id = null;
|
|
|
|
firstLoad = true;
|
|
|
|
flag_loading = true;
|
|
|
|
swiped = true;
|
|
|
|
asyncTask = new RetrievePeertubeNotificationsAsyncTask(LoginActivity.this, null, null, LoginActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
|
});
|
|
|
|
asyncTask = new RetrievePeertubeNotificationsAsyncTask(LoginActivity.this, null, max_id, LoginActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2020-06-30 13:33:43 +02:00
|
|
|
} else {
|
2020-06-30 11:38:06 +02:00
|
|
|
connected.setVisibility(View.GONE);
|
2020-07-01 15:19:24 +02:00
|
|
|
not_connected.setVisibility(View.VISIBLE);
|
2020-06-30 11:38:06 +02:00
|
|
|
}
|
|
|
|
|
2020-06-28 19:11:39 +02:00
|
|
|
|
|
|
|
connectionButton.setOnClickListener(v -> {
|
2020-06-29 15:43:35 +02:00
|
|
|
|
2020-06-29 16:43:20 +02:00
|
|
|
if (!android.util.Patterns.EMAIL_ADDRESS.matcher(login_uid.getText().toString().trim()).matches()) {
|
|
|
|
Toasty.error(LoginActivity.this, getString(R.string.email_error)).show();
|
|
|
|
return;
|
2020-06-28 19:11:39 +02:00
|
|
|
}
|
2020-06-29 16:43:20 +02:00
|
|
|
String[] emailArray = login_uid.getText().toString().split("@");
|
|
|
|
if (emailArray.length > 1 && !Arrays.asList(Helper.valideEmails).contains(emailArray[1])) {
|
|
|
|
Toasty.error(LoginActivity.this, getString(R.string.email_error_domain, emailArray[1])).show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
String host = emailArray[1];
|
|
|
|
String instance = Helper.getPeertubeUrl(host);
|
|
|
|
final HashMap<String, String> parameters = new HashMap<>();
|
|
|
|
connectionButton.setEnabled(false);
|
|
|
|
|
2020-06-28 19:11:39 +02:00
|
|
|
try {
|
2020-06-29 16:43:20 +02:00
|
|
|
instance = URLEncoder.encode(instance, "utf-8");
|
2020-06-28 19:11:39 +02:00
|
|
|
} catch (UnsupportedEncodingException e) {
|
2020-06-29 16:43:20 +02:00
|
|
|
Toasty.error(LoginActivity.this, getString(R.string.client_error), Toast.LENGTH_LONG).show();
|
2020-06-28 19:11:39 +02:00
|
|
|
}
|
2020-06-29 16:43:20 +02:00
|
|
|
actionToken = "/api/v1/oauth-clients/local";
|
|
|
|
parameters.clear();
|
|
|
|
parameters.put(Helper.CLIENT_NAME, Helper.CLIENT_NAME_VALUE);
|
|
|
|
parameters.put(Helper.REDIRECT_URIS, Helper.REDIRECT_CONTENT);
|
|
|
|
parameters.put(Helper.SCOPES, Helper.OAUTH_SCOPES_PEERTUBE);
|
|
|
|
parameters.put(Helper.WEBSITE, Helper.WEBSITE_VALUE);
|
|
|
|
String finalInstance = instance;
|
2020-06-28 19:11:39 +02:00
|
|
|
new Thread(() -> {
|
|
|
|
try {
|
2020-06-29 16:43:20 +02:00
|
|
|
String response = new HttpsConnection(LoginActivity.this).get("https://" + finalInstance + actionToken, 30, parameters, null);
|
|
|
|
JSONObject resobj;
|
|
|
|
try {
|
|
|
|
resobj = new JSONObject(response);
|
|
|
|
client_id = resobj.get(Helper.CLIENT_ID).toString();
|
|
|
|
client_secret = resobj.get(Helper.CLIENT_SECRET).toString();
|
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
|
|
editor.putString(Helper.CLIENT_ID, client_id);
|
|
|
|
editor.putString(Helper.CLIENT_SECRET, client_secret);
|
|
|
|
editor.apply();
|
|
|
|
parameters.clear();
|
|
|
|
parameters.put(Helper.CLIENT_ID, sharedpreferences.getString(Helper.CLIENT_ID, null));
|
|
|
|
parameters.put(Helper.CLIENT_SECRET, sharedpreferences.getString(Helper.CLIENT_SECRET, null));
|
|
|
|
parameters.put("grant_type", "password");
|
|
|
|
try {
|
|
|
|
parameters.put("username", URLEncoder.encode(login_uid.getText().toString().trim().toLowerCase(), "UTF-8"));
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
parameters.put("username", login_uid.getText().toString().trim().toLowerCase());
|
|
|
|
}
|
2020-06-28 19:11:39 +02:00
|
|
|
try {
|
2020-06-29 16:43:20 +02:00
|
|
|
parameters.put("password", URLEncoder.encode(login_passwd.getText().toString(), "UTF-8"));
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
parameters.put("password", login_passwd.getText().toString());
|
|
|
|
}
|
|
|
|
parameters.put("scope", "user");
|
|
|
|
String oauthUrl = "/api/v1/users/token";
|
|
|
|
try {
|
|
|
|
String responseLogin = new HttpsConnection(LoginActivity.this).post("https://" + finalInstance + oauthUrl, 30, parameters, null);
|
|
|
|
runOnUiThread(() -> {
|
|
|
|
JSONObject resobjLogin;
|
|
|
|
try {
|
|
|
|
resobjLogin = new JSONObject(responseLogin);
|
2020-06-30 11:38:06 +02:00
|
|
|
String token = resobjLogin.getString("access_token");
|
|
|
|
String refresh_token = resobjLogin.getString("refresh_token");
|
2020-06-29 16:43:20 +02:00
|
|
|
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token);
|
2020-06-30 11:38:06 +02:00
|
|
|
editor.putString(Helper.PREF_INSTANCE, host);
|
2020-06-29 16:43:20 +02:00
|
|
|
editor.apply();
|
|
|
|
//Update the account with the token;
|
|
|
|
new UpdateAccountInfoAsyncTask(LoginActivity.this, token, client_id, client_secret, refresh_token, host).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
|
} catch (JSONException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
runOnUiThread(() -> connectionButton.setEnabled(true));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (final Exception e) {
|
2020-06-28 19:11:39 +02:00
|
|
|
e.printStackTrace();
|
2020-06-29 16:43:20 +02:00
|
|
|
runOnUiThread(() -> {
|
|
|
|
connectionButton.setEnabled(true);
|
|
|
|
String message;
|
|
|
|
if (e.getLocalizedMessage() != null && e.getLocalizedMessage().trim().length() > 0)
|
|
|
|
message = e.getLocalizedMessage();
|
|
|
|
else if (e.getMessage() != null && e.getMessage().trim().length() > 0)
|
|
|
|
message = e.getMessage();
|
|
|
|
else
|
|
|
|
message = getString(R.string.client_error);
|
|
|
|
Toasty.error(LoginActivity.this, message, Toast.LENGTH_LONG).show();
|
|
|
|
});
|
2020-06-28 19:11:39 +02:00
|
|
|
}
|
2020-06-29 16:43:20 +02:00
|
|
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
runOnUiThread(() -> connectionButton.setEnabled(true));
|
|
|
|
}
|
2020-06-28 19:11:39 +02:00
|
|
|
} catch (final Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
runOnUiThread(() -> {
|
|
|
|
connectionButton.setEnabled(true);
|
2020-06-29 16:43:20 +02:00
|
|
|
String message = null;
|
|
|
|
if (e.getLocalizedMessage() != null) {
|
|
|
|
message = e.getMessage();
|
|
|
|
}
|
|
|
|
if (message == null) {
|
|
|
|
message = getString(R.string.client_error);
|
|
|
|
}
|
|
|
|
Toasty.error(LoginActivity.this, message, Toast.LENGTH_LONG).show();
|
2020-06-28 19:11:39 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}).start();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-06-29 16:43:20 +02:00
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
2020-06-28 19:11:39 +02:00
|
|
|
}
|
|
|
|
|
2020-06-29 16:43:20 +02:00
|
|
|
|
2020-06-28 19:11:39 +02:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
if (item.getItemId() == android.R.id.home) {
|
|
|
|
finish();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
2020-07-01 15:08:42 +02:00
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
|
|
|
super.onDestroy();
|
|
|
|
if (asyncTask != null && !asyncTask.isCancelled()) {
|
|
|
|
asyncTask.cancel(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRetrievePeertubeNotifications(APIResponse apiResponse, Account account) {
|
|
|
|
mainLoader.setVisibility(View.GONE);
|
|
|
|
nextElementLoader.setVisibility(View.GONE);
|
|
|
|
if (apiResponse.getError() != null) {
|
|
|
|
Toasty.error(LoginActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
|
|
|
|
flag_loading = false;
|
|
|
|
swipeRefreshLayout.setRefreshing(false);
|
|
|
|
swiped = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int previousPosition = notifications.size();
|
|
|
|
max_id = apiResponse.getMax_id();
|
|
|
|
List<PeertubeNotification> notifications = apiResponse.getPeertubeNotifications();
|
|
|
|
if (!swiped && firstLoad && (notifications == null || notifications.size() == 0))
|
|
|
|
textviewNoAction.setVisibility(View.VISIBLE);
|
|
|
|
else
|
|
|
|
textviewNoAction.setVisibility(View.GONE);
|
|
|
|
if (swiped) {
|
|
|
|
if (previousPosition > 0) {
|
|
|
|
this.notifications.subList(0, previousPosition).clear();
|
|
|
|
notificationsListAdapter.notifyItemRangeRemoved(0, previousPosition);
|
|
|
|
}
|
|
|
|
swiped = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (notifications != null && notifications.size() > 0) {
|
|
|
|
this.notifications.addAll(notifications);
|
|
|
|
notificationsListAdapter.notifyItemRangeInserted(previousPosition, notifications.size());
|
|
|
|
} else {
|
|
|
|
if (firstLoad)
|
|
|
|
textviewNoAction.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
swipeRefreshLayout.setRefreshing(false);
|
|
|
|
firstLoad = false;
|
|
|
|
//The initial call comes from a classic tab refresh
|
|
|
|
flag_loading = (max_id == null);
|
|
|
|
}
|
2020-06-28 19:11:39 +02:00
|
|
|
|
|
|
|
}
|