diff --git a/app/src/main/java/app/fedilab/fedilabtube/AllPlaylistsActivity.java b/app/src/main/java/app/fedilab/fedilabtube/AllPlaylistsActivity.java index 42d7100..1bb7d9e 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/AllPlaylistsActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/AllPlaylistsActivity.java @@ -15,7 +15,6 @@ package app.fedilab.fedilabtube; * see . */ 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; diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeAPI.java b/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeAPI.java index 2692d0d..686ffb1 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeAPI.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeAPI.java @@ -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"); diff --git a/app/src/main/java/app/fedilab/fedilabtube/drawer/AccountsListAdapter.java b/app/src/main/java/app/fedilab/fedilabtube/drawer/AccountsListAdapter.java index 567e209..d2201d5 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/drawer/AccountsListAdapter.java +++ b/app/src/main/java/app/fedilab/fedilabtube/drawer/AccountsListAdapter.java @@ -138,16 +138,15 @@ public class AccountsListAdapter extends RecyclerView.Adapter= 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 { switch (item.getItemId()) { case R.id.action_delete: @@ -310,7 +312,6 @@ public class AccountsListAdapter extends RecyclerView.Adapter { - 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(); - channelCreation.setDisplayName(display_name.getText().toString().trim()); - channelCreation.setName(name.getText().toString().trim()); - if (description.getText() != null && description.getText().toString().trim().length() > 0) { - channelCreation.setDescription(description.getText().toString().trim()); - } - new Thread(() -> { - try { - if (oldChannelValues == null) { - new PeertubeAPI(context).createChannel(channelCreation); - } else { - new PeertubeAPI(context).updateChannel(name + "@" + Helper.getLiveInstance(context), channelCreation); - } - Handler mainHandler = new Handler(Looper.getMainLooper()); - Runnable myRunnable = () -> { - - if (getActivity() == null) - return; - Account channel = new Account(); - channel.setAcct(channelCreation.getName() + "@" + Helper.getLiveInstance(context)); - channel.setUsername(channelCreation.getName()); - channel.setDisplay_name(channelCreation.getDisplayName()); - channel.setNote(channelCreation.getDescription()); - accounts.add(0, channel); - accountsListAdapter.notifyItemInserted(0); - action_button.setEnabled(true); - }; - mainHandler.post(myRunnable); - } catch (HttpsConnection.HttpsConnectionException e) { - - e.printStackTrace(); - Handler mainHandler = new Handler(Looper.getMainLooper()); - Runnable myRunnable = () -> { - action_button.setEnabled(true); - if (e.getMessage() != null) { - Toasty.error(context, e.getMessage(), Toast.LENGTH_LONG).show(); - } else { - Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show(); - } - }; - mainHandler.post(myRunnable); - } - }).start(); - - dialog.dismiss(); - action_button.setEnabled(false); - } else { - Toasty.error(context, context.getString(R.string.error_display_name_channel), Toast.LENGTH_LONG).show(); - } - - }); + 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(); + channelCreation.setDisplayName(display_name.getText().toString().trim()); + channelCreation.setName(name.getText().toString().trim()); + if (description.getText() != null && description.getText().toString().trim().length() > 0) { + channelCreation.setDescription(description.getText().toString().trim()); + } + new Thread(() -> { + try { + if (oldChannelValues == null) { + new PeertubeAPI(context).createChannel(channelCreation); + } else { + 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()); + channel.setDisplay_name(channelCreation.getDisplayName()); + 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); + } catch (HttpsConnection.HttpsConnectionException e) { + + e.printStackTrace(); + Handler mainHandler = new Handler(Looper.getMainLooper()); + Runnable myRunnable = () -> { + action_button.setEnabled(true); + if (e.getMessage() != null) { + Toasty.error(context, e.getMessage(), Toast.LENGTH_LONG).show(); + } else { + Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show(); + } + }; + mainHandler.post(myRunnable); + } + }).start(); + alertDialog.dismiss(); + action_button.setEnabled(false); + } else { + Toasty.error(context, context.getString(R.string.error_display_name_channel), Toast.LENGTH_LONG).show(); + } + }); + }); if (oldChannelValues == null) { alertDialog.setTitle(getString(R.string.action_channel_create)); } else { diff --git a/app/src/main/res/layout/drawer_account.xml b/app/src/main/res/layout/drawer_account.xml index b3a5cf3..23d898a 100644 --- a/app/src/main/res/layout/drawer_account.xml +++ b/app/src/main/res/layout/drawer_account.xml @@ -38,26 +38,13 @@ android:layout_weight="1" android:orientation="vertical"> - - - - - - + android:singleLine="true" + android:textAppearance="@style/TextAppearance.AppCompat.Body1" + android:textSize="18sp" />