Fix channel update
This commit is contained in:
parent
d02fdba671
commit
5660fb15e5
|
@ -15,7 +15,6 @@ package app.fedilab.fedilabtube;
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
@ -55,7 +54,6 @@ import app.fedilab.fedilabtube.client.entities.Account;
|
|||
import app.fedilab.fedilabtube.client.entities.Playlist;
|
||||
import app.fedilab.fedilabtube.client.entities.PlaylistElement;
|
||||
import app.fedilab.fedilabtube.drawer.PlaylistAdapter;
|
||||
import app.fedilab.fedilabtube.helper.Helper;
|
||||
import app.fedilab.fedilabtube.viewmodel.ChannelsVM;
|
||||
import app.fedilab.fedilabtube.viewmodel.PlaylistsVM;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
|
|
@ -31,7 +31,6 @@ import java.io.UnsupportedEncodingException;
|
|||
import java.net.URLEncoder;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.text.Format;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
@ -442,19 +441,19 @@ public class PeertubeAPI {
|
|||
private static Account parseAccountResponsePeertube(JSONObject accountObject) {
|
||||
Account account = new Account();
|
||||
try {
|
||||
account.setId(accountObject.get("id").toString());
|
||||
account.setUuid(accountObject.get("id").toString());
|
||||
account.setUsername(accountObject.get("name").toString());
|
||||
account.setAcct(accountObject.get("name").toString() + "@" + accountObject.get("host"));
|
||||
account.setDisplay_name(accountObject.get("name").toString());
|
||||
account.setHost(accountObject.get("host").toString());
|
||||
account.setId(accountObject.getString("id"));
|
||||
account.setUuid(accountObject.getString("id"));
|
||||
account.setUsername(accountObject.getString("name"));
|
||||
account.setAcct(accountObject.getString("name") + "@" + accountObject.get("host"));
|
||||
account.setDisplay_name(accountObject.get("displayName").toString());
|
||||
account.setHost(accountObject.getString("host"));
|
||||
account.setSocial("PEERTUBE");
|
||||
account.setInstance(accountObject.getString("host"));
|
||||
if (accountObject.has("ownerAccount")) {
|
||||
account.setchannelOwner(parseAccountResponsePeertube(accountObject.getJSONObject("ownerAccount")));
|
||||
}
|
||||
if (accountObject.has("createdAt"))
|
||||
account.setCreated_at(Helper.mstStringToDate(accountObject.get("createdAt").toString()));
|
||||
account.setCreated_at(Helper.mstStringToDate(accountObject.getString("createdAt")));
|
||||
else
|
||||
account.setCreated_at(new Date());
|
||||
if (accountObject.has("followersCount"))
|
||||
|
@ -467,16 +466,16 @@ public class PeertubeAPI {
|
|||
account.setFollowing_count(0);
|
||||
account.setStatuses_count(0);
|
||||
if (accountObject.has("description"))
|
||||
account.setNote(accountObject.get("description").toString());
|
||||
account.setNote(accountObject.getString("description"));
|
||||
else
|
||||
account.setNote("");
|
||||
|
||||
if (accountObject.has("url")) {
|
||||
account.setUrl(accountObject.get("url").toString());
|
||||
account.setUrl(accountObject.getString("url"));
|
||||
}
|
||||
if (accountObject.has("avatar") && !accountObject.isNull("avatar")) {
|
||||
account.setAvatar(accountObject.getJSONObject("avatar").get("path").toString());
|
||||
account.setAvatar_static(accountObject.getJSONObject("avatar").get("path").toString());
|
||||
account.setAvatar(accountObject.getJSONObject("avatar").getString("path"));
|
||||
account.setAvatar_static(accountObject.getJSONObject("avatar").getString("path"));
|
||||
} else {
|
||||
account.setAvatar("null");
|
||||
account.setAvatar_static("null");
|
||||
|
|
|
@ -138,16 +138,15 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
holder.account_action.hide();
|
||||
}
|
||||
|
||||
if (account.getDisplay_name() != null && !account.getDisplay_name().trim().equals(""))
|
||||
holder.account_dn.setText(account.getDisplay_name());
|
||||
else
|
||||
holder.account_dn.setText(account.getUsername().replace("@", ""));
|
||||
holder.account_un.setText(String.format("@%s", account.getUsername()));
|
||||
holder.account_ac.setText(account.getAcct());
|
||||
if (account.getUsername().equals(account.getAcct()))
|
||||
holder.account_ac.setVisibility(View.GONE);
|
||||
else
|
||||
holder.account_ac.setVisibility(View.VISIBLE);
|
||||
if (account.getNote() == null) {
|
||||
account.setNote("");
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
holder.account_ds.setText(Html.fromHtml(account.getNote(), Html.FROM_HTML_MODE_LEGACY));
|
||||
else
|
||||
|
@ -173,6 +172,9 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
PopupMenu popup = new PopupMenu(context, holder.more_actions);
|
||||
popup.getMenuInflater()
|
||||
.inflate(R.menu.playlist_menu, popup.getMenu());
|
||||
if (accounts.size() == 1) {
|
||||
popup.getMenu().findItem(R.id.action_delete).setEnabled(false);
|
||||
}
|
||||
popup.setOnMenuItemClickListener(item -> {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_delete:
|
||||
|
@ -310,7 +312,6 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
ImageView account_pp;
|
||||
TextView account_ac;
|
||||
TextView account_dn;
|
||||
TextView account_un;
|
||||
TextView account_ds;
|
||||
TextView account_sc;
|
||||
TextView account_fgc;
|
||||
|
@ -325,7 +326,6 @@ public class AccountsListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
account_pp = itemView.findViewById(R.id.account_pp);
|
||||
account_dn = itemView.findViewById(R.id.account_dn);
|
||||
account_ac = itemView.findViewById(R.id.account_ac);
|
||||
account_un = itemView.findViewById(R.id.account_un);
|
||||
account_ds = itemView.findViewById(R.id.account_ds);
|
||||
account_sc = itemView.findViewById(R.id.account_sc);
|
||||
account_fgc = itemView.findViewById(R.id.account_fgc);
|
||||
|
|
|
@ -24,6 +24,7 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
|
@ -257,8 +258,17 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
|
|||
display_name.setText(oldChannelValues.getDisplayName());
|
||||
name.setText(oldChannelValues.getName());
|
||||
description.setText(oldChannelValues.getDescription());
|
||||
name.setEnabled(false);
|
||||
}
|
||||
dialogBuilder.setPositiveButton(R.string.validate, (dialog, id) -> {
|
||||
dialogBuilder.setPositiveButton(R.string.validate, null);
|
||||
dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
|
||||
|
||||
AlertDialog alertDialog = dialogBuilder.create();
|
||||
|
||||
alertDialog.setOnShowListener(dialogInterface -> {
|
||||
|
||||
Button button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||
button.setOnClickListener(view -> {
|
||||
if (display_name.getText() != null && display_name.getText().toString().trim().length() > 0 && name.getText() != null && name.getText().toString().trim().length() > 0) {
|
||||
|
||||
ChannelCreation channelCreation = new ChannelCreation();
|
||||
|
@ -272,13 +282,14 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
|
|||
if (oldChannelValues == null) {
|
||||
new PeertubeAPI(context).createChannel(channelCreation);
|
||||
} else {
|
||||
new PeertubeAPI(context).updateChannel(name + "@" + Helper.getLiveInstance(context), channelCreation);
|
||||
new PeertubeAPI(context).updateChannel(channelCreation.getName() + "@" + Helper.getLiveInstance(context), channelCreation);
|
||||
}
|
||||
Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable myRunnable = () -> {
|
||||
|
||||
if (getActivity() == null)
|
||||
return;
|
||||
if (oldChannelValues == null) {
|
||||
Account channel = new Account();
|
||||
channel.setAcct(channelCreation.getName() + "@" + Helper.getLiveInstance(context));
|
||||
channel.setUsername(channelCreation.getName());
|
||||
|
@ -286,6 +297,18 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
|
|||
channel.setNote(channelCreation.getDescription());
|
||||
accounts.add(0, channel);
|
||||
accountsListAdapter.notifyItemInserted(0);
|
||||
} else {
|
||||
int position = 0;
|
||||
for (Account account : accounts) {
|
||||
if (account.getId().compareTo(oldChannelValues.getId()) == 0) {
|
||||
account.setNote(channelCreation.getDescription());
|
||||
account.setDisplay_name(channelCreation.getDisplayName());
|
||||
break;
|
||||
}
|
||||
position++;
|
||||
}
|
||||
accountsListAdapter.notifyItemChanged(position);
|
||||
}
|
||||
action_button.setEnabled(true);
|
||||
};
|
||||
mainHandler.post(myRunnable);
|
||||
|
@ -304,17 +327,13 @@ public class DisplayAccountsFragment extends Fragment implements AccountsListAda
|
|||
mainHandler.post(myRunnable);
|
||||
}
|
||||
}).start();
|
||||
|
||||
dialog.dismiss();
|
||||
alertDialog.dismiss();
|
||||
action_button.setEnabled(false);
|
||||
} else {
|
||||
Toasty.error(context, context.getString(R.string.error_display_name_channel), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
});
|
||||
dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
|
||||
|
||||
AlertDialog alertDialog = dialogBuilder.create();
|
||||
});
|
||||
if (oldChannelValues == null) {
|
||||
alertDialog.setTitle(getString(R.string.action_channel_create));
|
||||
} else {
|
||||
|
|
|
@ -38,11 +38,6 @@
|
|||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/account_dn"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -51,14 +46,6 @@
|
|||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
||||
android:textSize="18sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/account_un"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:textSize="14sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/account_ac"
|
||||
android:layout_width="match_parent"
|
||||
|
|
Loading…
Reference in New Issue