diff --git a/app/src/acad/res/values/strings.xml b/app/src/acad/res/values/strings.xml
index 502b19a..c74c3a5 100644
--- a/app/src/acad/res/values/strings.xml
+++ b/app/src/acad/res/values/strings.xml
@@ -236,4 +236,6 @@
No opinion
Pickup languages
Mise à jour des informations
+
+ Liste des comptes
diff --git a/app/src/full/res/values/strings.xml b/app/src/full/res/values/strings.xml
index 2b30f00..d69ea1b 100644
--- a/app/src/full/res/values/strings.xml
+++ b/app/src/full/res/values/strings.xml
@@ -252,4 +252,7 @@
Pickup categories
Pickup languages
Update information
+
+ Add an account
+ List of accounts
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 574121e..9b64f31 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -5,15 +5,15 @@
-
+
+
accounts = new AccountDAO(AccountActivity.this, db).getAllAccount();
+
+ AlertDialog.Builder builderSingle = new AlertDialog.Builder(AccountActivity.this);
+ builderSingle.setTitle(getString(R.string.list_of_accounts));
+ final OwnAccountsAdapter accountsListAdapter = new OwnAccountsAdapter(AccountActivity.this, accounts);
+ final Account[] accountArray = new Account[accounts.size()];
+ int i = 0;
+ for (Account account : accounts) {
+ accountArray[i] = account;
+ i++;
+ }
+ builderSingle.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
+ builderSingle.setPositiveButton(R.string.add_account, (dialog, which) -> {
+ Intent intent = new Intent(AccountActivity.this, LoginActivity.class);
+ startActivity(intent);
+ finish();
+ });
+ builderSingle.setAdapter(accountsListAdapter, (dialog, which) -> {
+ final Account account = accountArray[which];
+ SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
+ SharedPreferences.Editor editor = sharedpreferences.edit();
+ editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, account.getToken());
+ editor.putString(Helper.PREF_INSTANCE, account.getInstance());
+ editor.putString(Helper.PREF_KEY_ID, account.getId());
+ editor.apply();
+ dialog.dismiss();
+ Intent intent = new Intent(AccountActivity.this, MainActivity.class);
+ startActivity(intent);
+ finish();
+ });
+ builderSingle.show();
}
return super.onOptionsItemSelected(item);
}
diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeRegisterActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeRegisterActivity.java
index 1a05923..b785210 100644
--- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeRegisterActivity.java
+++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeRegisterActivity.java
@@ -83,6 +83,9 @@ public class PeertubeRegisterActivity extends AppCompatActivity {
if (BuildConfig.full_instances) {
login_instance_container.setVisibility(View.VISIBLE);
title_login_instance.setVisibility(View.VISIBLE);
+ } else {
+ login_instance_container.setVisibility(View.GONE);
+ title_login_instance.setVisibility(View.GONE);
}
username.setOnFocusChangeListener((view, focused) -> {
@@ -161,7 +164,11 @@ public class PeertubeRegisterActivity extends AppCompatActivity {
signup.setEnabled(false);
if (BuildConfig.full_instances) {
- instance = login_instance.getText().toString();
+ if (login_instance.getText() != null) {
+ instance = login_instance.getText().toString();
+ } else {
+ instance = "";
+ }
} else {
String host = emailArray[1];
instance = Helper.getPeertubeUrl(host);
diff --git a/app/src/main/java/app/fedilab/fedilabtube/drawer/OwnAccountsAdapter.java b/app/src/main/java/app/fedilab/fedilabtube/drawer/OwnAccountsAdapter.java
new file mode 100644
index 0000000..93fcc77
--- /dev/null
+++ b/app/src/main/java/app/fedilab/fedilabtube/drawer/OwnAccountsAdapter.java
@@ -0,0 +1,95 @@
+package app.fedilab.fedilabtube.drawer;
+/* 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 . */
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+
+
+import java.util.List;
+
+import app.fedilab.fedilabtube.R;
+import app.fedilab.fedilabtube.client.entities.Account;
+import app.fedilab.fedilabtube.helper.Helper;
+
+
+public class OwnAccountsAdapter extends ArrayAdapter {
+
+ private List accounts;
+ private LayoutInflater layoutInflater;
+
+ public OwnAccountsAdapter(Context context, List accounts) {
+ super(context, android.R.layout.simple_list_item_1, accounts);
+ this.accounts = accounts;
+ layoutInflater = LayoutInflater.from(context);
+ }
+
+
+ @Override
+ public int getCount() {
+ return accounts.size();
+ }
+
+ @Override
+ public Account getItem(int position) {
+ return accounts.get(position);
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return position;
+ }
+
+ @NonNull
+ @Override
+ public View getView(final int position, View convertView, @NonNull ViewGroup parent) {
+
+ final Account account = accounts.get(position);
+ final ViewHolder holder;
+ if (convertView == null) {
+ convertView = layoutInflater.inflate(R.layout.drawer_account_owner, parent, false);
+ holder = new ViewHolder();
+ holder.account_pp = convertView.findViewById(R.id.account_pp);
+ holder.account_un = convertView.findViewById(R.id.account_un);
+
+ holder.account_container = convertView.findViewById(R.id.account_container);
+ convertView.setTag(holder);
+ } else {
+ holder = (ViewHolder) convertView.getTag();
+ }
+
+ holder.account_un.setText(String.format("@%s", account.getAcct()));
+ //Profile picture
+ Helper.loadGiF(holder.account_pp.getContext(), account.getAvatar().compareTo("null") != 0 ? "https://" + account.getInstance() + account.getAvatar() : "null", holder.account_pp);
+ return convertView;
+ }
+
+
+ private static class ViewHolder {
+ ImageView account_pp;
+ TextView account_un;
+ LinearLayout account_container;
+ }
+
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java b/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java
index 9922918..3cfc6e0 100644
--- a/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java
+++ b/app/src/main/java/app/fedilab/fedilabtube/helper/Helper.java
@@ -57,6 +57,7 @@ import java.util.TimeZone;
import java.util.regex.Pattern;
import app.fedilab.fedilabtube.BuildConfig;
+import app.fedilab.fedilabtube.LoginActivity;
import app.fedilab.fedilabtube.MainActivity;
import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.WebviewActivity;
@@ -627,29 +628,38 @@ public class Helper {
* Log out the authenticated user by removing its token
*
* @param activity Activity
+ * @param account Account
*/
public static void logoutCurrentUser(Activity activity, Account account) {
- SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
-
+ SharedPreferences sharedpreferences = activity.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
+ //Current user
SQLiteDatabase db = Sqlite.getInstance(activity.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
+
if (account != null) {
new AccountDAO(activity, db).removeUser(account);
}
+ Account newAccount = new AccountDAO(activity, db).getLastUsedAccount();
SharedPreferences.Editor editor = sharedpreferences.edit();
- editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, null);
- editor.putString(Helper.CLIENT_ID, null);
- editor.putString(Helper.CLIENT_SECRET, null);
- editor.putString(Helper.PREF_KEY_ID, null);
- editor.putBoolean(Helper.PREF_IS_MODERATOR, false);
- editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, false);
- editor.putString(Helper.PREF_INSTANCE, null);
- editor.putString(Helper.ID, null);
- editor.apply();
- Intent mainActivity = new Intent(activity, MainActivity.class);
- mainActivity.putExtra(Helper.INTENT_ACTION, Helper.ADD_USER_INTENT);
- activity.startActivity(mainActivity);
- activity.finish();
-
+ if (newAccount == null) {
+ editor.putString(PREF_KEY_OAUTH_TOKEN, null);
+ editor.putString(CLIENT_ID, null);
+ editor.putString(CLIENT_SECRET, null);
+ editor.putString(PREF_KEY_ID, null);
+ editor.putString(PREF_INSTANCE, null);
+ editor.putString(ID, null);
+ editor.apply();
+ Intent loginActivity = new Intent(activity, LoginActivity.class);
+ activity.startActivity(loginActivity);
+ activity.finish();
+ } else {
+ editor.putString(PREF_KEY_OAUTH_TOKEN, newAccount.getToken());
+ editor.putString(PREF_KEY_ID, newAccount.getId());
+ editor.putString(PREF_INSTANCE, newAccount.getInstance().trim());
+ editor.commit();
+ Intent changeAccount = new Intent(activity, MainActivity.class);
+ changeAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
+ activity.startActivity(changeAccount);
+ }
}
diff --git a/app/src/main/java/app/fedilab/fedilabtube/services/RetrieveInfoService.java b/app/src/main/java/app/fedilab/fedilabtube/services/RetrieveInfoService.java
index 10cba08..9f79951 100644
--- a/app/src/main/java/app/fedilab/fedilabtube/services/RetrieveInfoService.java
+++ b/app/src/main/java/app/fedilab/fedilabtube/services/RetrieveInfoService.java
@@ -15,7 +15,10 @@ package app.fedilab.fedilabtube.services;
* see . */
import android.app.Notification;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
import android.app.Service;
+import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
@@ -25,6 +28,7 @@ import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
import java.util.LinkedHashMap;
+import java.util.Objects;
import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.client.HttpsConnection;
@@ -37,7 +41,7 @@ import static app.fedilab.fedilabtube.MainActivity.peertubeInformation;
public class RetrieveInfoService extends Service implements NetworkStateReceiver.NetworkStateReceiverListener {
- static String NOTIFICATION_CHANNEL_ID = "update_info";
+ static String NOTIFICATION_CHANNEL_ID = "update_info_peertube";
private NetworkStateReceiver networkStateReceiver;
@@ -53,19 +57,26 @@ public class RetrieveInfoService extends Service implements NetworkStateReceiver
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- Notification.Builder builder = new Notification.Builder(this, NOTIFICATION_CHANNEL_ID)
+ NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
+ getString(R.string.notification_channel_name),
+ NotificationManager.IMPORTANCE_DEFAULT);
+ channel.setSound(null, null);
+
+ ((NotificationManager) Objects.requireNonNull(getSystemService(Context.NOTIFICATION_SERVICE))).createNotificationChannel(channel);
+ android.app.Notification notification = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification_tubelab)
.setContentTitle(getString(R.string.app_name))
.setContentText(getString(R.string.notification_channel_name))
- .setAutoCancel(true);
+ .setAutoCancel(true).build();
- Notification notification = builder.build();
startForeground(1, notification);
} else {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
.setContentTitle(getString(R.string.app_name))
+ .setDefaults(Notification.DEFAULT_ALL)
.setContentText(getString(R.string.notification_channel_name))
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setAutoCancel(true);
diff --git a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/AccountsVM.java b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/AccountsVM.java
index 2f12563..a285eac 100644
--- a/app/src/main/java/app/fedilab/fedilabtube/viewmodel/AccountsVM.java
+++ b/app/src/main/java/app/fedilab/fedilabtube/viewmodel/AccountsVM.java
@@ -73,6 +73,7 @@ public class AccountsVM extends AndroidViewModel {
CHANNEL,
MUTED,
SINGLE_ACCOUNT,
- SINGLE_CHANNEL
+ SINGLE_CHANNEL,
+ OWN_ACCOUNTS
}
}
diff --git a/app/src/main/res/drawable-hdpi/ic_notification_tubelab.png b/app/src/main/res/drawable-hdpi/ic_notification_tubelab.png
index a58f6a5..27f4dd8 100644
Binary files a/app/src/main/res/drawable-hdpi/ic_notification_tubelab.png and b/app/src/main/res/drawable-hdpi/ic_notification_tubelab.png differ
diff --git a/app/src/main/res/drawable-mdpi/ic_notification_tubelab.png b/app/src/main/res/drawable-mdpi/ic_notification_tubelab.png
index 5cfd622..d7cd8a2 100644
Binary files a/app/src/main/res/drawable-mdpi/ic_notification_tubelab.png and b/app/src/main/res/drawable-mdpi/ic_notification_tubelab.png differ
diff --git a/app/src/main/res/drawable-xhdpi/ic_notification_tubelab.png b/app/src/main/res/drawable-xhdpi/ic_notification_tubelab.png
index 347f385..8633430 100644
Binary files a/app/src/main/res/drawable-xhdpi/ic_notification_tubelab.png and b/app/src/main/res/drawable-xhdpi/ic_notification_tubelab.png differ
diff --git a/app/src/main/res/drawable-xxhdpi/ic_notification_tubelab.png b/app/src/main/res/drawable-xxhdpi/ic_notification_tubelab.png
index f928b4f..e9879d9 100644
Binary files a/app/src/main/res/drawable-xxhdpi/ic_notification_tubelab.png and b/app/src/main/res/drawable-xxhdpi/ic_notification_tubelab.png differ
diff --git a/app/src/main/res/drawable-xxxhdpi/ic_notification_tubelab.png b/app/src/main/res/drawable-xxxhdpi/ic_notification_tubelab.png
new file mode 100644
index 0000000..21a32b0
Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_notification_tubelab.png differ
diff --git a/app/src/main/res/drawable/ic_baseline_person_add_24.xml b/app/src/main/res/drawable/ic_baseline_person_add_24.xml
new file mode 100644
index 0000000..842c6df
--- /dev/null
+++ b/app/src/main/res/drawable/ic_baseline_person_add_24.xml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml
index b839da2..1205045 100644
--- a/app/src/main/res/layout/activity_login.xml
+++ b/app/src/main/res/layout/activity_login.xml
@@ -85,7 +85,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/title_instance_login"
- android:inputType="textWebEditText"
+ android:inputType="textWebEmailAddress"
android:singleLine="true" />
diff --git a/app/src/main/res/layout/drawer_account_owner.xml b/app/src/main/res/layout/drawer_account_owner.xml
new file mode 100644
index 0000000..4f21717
--- /dev/null
+++ b/app/src/main/res/layout/drawer_account_owner.xml
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/menu/main_profile.xml b/app/src/main/res/menu/main_profile.xml
new file mode 100644
index 0000000..0570d4a
--- /dev/null
+++ b/app/src/main/res/menu/main_profile.xml
@@ -0,0 +1,9 @@
+
+