Add comments

This commit is contained in:
stom79 2019-01-25 16:15:35 +01:00
parent aeeee5b44b
commit c7fca0f640
6 changed files with 159 additions and 5 deletions

View File

@ -17,6 +17,7 @@ package fr.gouv.etalab.mastodon.activities;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
@ -41,9 +42,11 @@ import android.text.Html;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
@ -83,6 +86,7 @@ import fr.gouv.etalab.mastodon.asynctasks.RetrievePeertubeSingleCommentsAsyncTas
import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoAsyncTask;
import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.APIResponse;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.Error;
import fr.gouv.etalab.mastodon.client.Entities.Peertube;
import fr.gouv.etalab.mastodon.client.Entities.Results;
@ -93,6 +97,7 @@ import fr.gouv.etalab.mastodon.helper.FullScreenMediaController;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
import fr.gouv.etalab.mastodon.interfaces.OnRetrievePeertubeInterface;
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
import fr.gouv.etalab.mastodon.sqlite.PeertubeFavoritesDAO;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
import fr.gouv.etalab.mastodon.webview.MastalabWebChromeClient;
@ -129,6 +134,10 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
private TextView resolution;
private DefaultTrackSelector trackSelector;
private int mode;
private LinearLayout write_comment_container;
private ImageView my_pp, send;
private TextView add_comment_read;
private EditText add_comment_write;
@Override
@ -164,7 +173,45 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
peertube_information_container = findViewById(R.id.peertube_information_container);
WebView webview_video = findViewById(R.id.webview_video);
playerView = findViewById(R.id.media_video);
write_comment_container = findViewById(R.id.write_comment_container);
my_pp = findViewById(R.id.my_pp);
add_comment_read = findViewById(R.id.add_comment_read);
add_comment_write = findViewById(R.id.add_comment_write);
send = findViewById(R.id.send);
add_comment_read.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
add_comment_read.setVisibility(View.GONE);
add_comment_write.setVisibility(View.VISIBLE);
send.setVisibility(View.VISIBLE);
add_comment_write.requestFocus();
add_comment_write.setSelection(add_comment_write.getText().length());
}
});
Helper.changeDrawableColor(getApplicationContext(), send, R.color.mastodonC4);
if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE){
write_comment_container.setVisibility(View.GONE);
}
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String comment = add_comment_write.getText().toString();
if( comment.trim().length() > 0 ) {
new PostActionAsyncTask(getApplicationContext(), API.StatusAction.PEERTUBECOMMENT, peertube.getId(), null, comment, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
add_comment_write.setText("");
add_comment_read.setVisibility(View.VISIBLE);
add_comment_write.setVisibility(View.GONE);
send.setVisibility(View.GONE);
add_comment_read.requestFocus();
}
}
});
String prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
Account account = new AccountDAO(getApplicationContext(), db).getAccountByToken(prefKeyOauthTokenT);
Helper.loadGiF(getApplicationContext(), account.getAvatar(), my_pp);
Bundle b = getIntent().getExtras();
if(b != null) {
peertubeInstance = b.getString("peertube_instance", null);
@ -271,7 +318,34 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
}
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
View v = getCurrentFocus();
if ((ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_MOVE) &&
v instanceof EditText &&
v.getId() == R.id.add_comment_write) {
int scrcoords[] = new int[2];
v.getLocationOnScreen(scrcoords);
float x = ev.getRawX() + v.getLeft() - scrcoords[0];
float y = ev.getRawY() + v.getTop() - scrcoords[1];
if (x < v.getLeft() || x > v.getRight() || y < v.getTop() || y > v.getBottom()) {
add_comment_read.setVisibility(View.VISIBLE);
add_comment_write.setVisibility(View.GONE);
send.setVisibility(View.GONE);
hideKeyboard(PeertubeActivity.this);
}
}
return super.dispatchTouchEvent(ev);
}
public static void hideKeyboard(Activity activity) {
if (activity != null && activity.getWindow() != null && activity.getWindow().getDecorView() != null) {
InputMethodManager imm = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(activity.getWindow().getDecorView().getWindowToken(), 0);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
@ -282,6 +356,11 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if( theme == THEME_LIGHT)
Helper.colorizeIconMenu(menu, R.color.black);
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE){
MenuItem item = menu.findItem(R.id.action_comment);
if( item != null)
item.setVisible(false);
}
return true;
}
@Override
@ -398,13 +477,15 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
}
peertube = apiResponse.getPeertubes().get(0);
if( peertube.isCommentsEnabled())
if( peertube.isCommentsEnabled()) {
new RetrievePeertubeSingleCommentsAsyncTask(PeertubeActivity.this, peertubeInstance, videoId, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else {
write_comment_container.setVisibility(View.VISIBLE);
}else {
RelativeLayout no_action = findViewById(R.id.no_action);
TextView no_action_text = findViewById(R.id.no_action_text);
no_action_text.setText(getString(R.string.comment_no_allowed_peertube));
no_action.setVisibility(View.VISIBLE);
write_comment_container.setVisibility(View.GONE);
}
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
@ -577,13 +658,10 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
return;
}
List<Status> statuses = apiResponse.getStatuses();
RelativeLayout no_action = findViewById(R.id.no_action);
RecyclerView lv_comments = findViewById(R.id.peertube_comments);
if( statuses == null || statuses.size() == 0){
no_action.setVisibility(View.VISIBLE);
lv_comments.setVisibility(View.GONE);
}else {
no_action.setVisibility(View.GONE);
lv_comments.setVisibility(View.VISIBLE);
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean isOnWifi = Helper.isOnWIFI(PeertubeActivity.this);

View File

@ -2722,6 +2722,9 @@ public class Helper {
return;
}
}
if( url != null && url.startsWith("/")){
url = Helper.getLiveInstanceWithProtocol(context) + url;
}
if( url == null || url.equals("null") || url.contains("missing.png") || url.contains(".svg")) {
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) {
try {

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M2.01,21L23,12 2.01,3 2,10l15,2 -15,2z"/>
</vector>

View File

@ -22,6 +22,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"
tools:context=".activities.PeertubeActivity">
<LinearLayout
@ -188,6 +189,64 @@
android:id="@+id/peertube_description"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:id="@+id/write_comment_container"
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:visibility="gone"
android:layout_gravity="center_vertical"
android:orientation="horizontal"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:contentDescription="@string/profile_picture"
android:id="@+id/my_pp"
android:layout_width="40dp"
android:layout_height="40dp" />
<ImageView
android:contentDescription="@string/send_comment"
android:id="@+id/send"
android:layout_marginTop="5dp"
android:visibility="gone"
android:src="@drawable/ic_send"
android:layout_width="30dp"
android:layout_height="30dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_height="wrap_content">
<TextView
android:id="@+id/add_comment_read"
android:text="@string/add_public_comment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:visibility="gone"
android:hint="@string/add_public_comment"
android:id="@+id/add_comment_write"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="always"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
android:focusable="true"
android:focusableInTouchMode="true"
android:maxLines="4"
android:inputType="textMultiLine" />
</LinearLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/peertube_comments"
android:layout_width="match_parent"

View File

@ -43,10 +43,13 @@
android:contentDescription="@string/close" />
<TextView
android:layout_width="wrap_content"
android:scrollHorizontally="true"
android:ellipsize="end"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content"
android:textColor="?attr/actionBarTextColor"
android:textSize="16sp"
android:maxLines="1"
android:id="@+id/toolbar_title" />
</android.support.v7.widget.Toolbar>

View File

@ -860,6 +860,8 @@
<string name="toot_select_import">Select the file to import</string>
<string name="toot_select_file_error">An error occurred when selecting the backup file!</string>
<string name="data_import_start">Please, don\'t kill the app while processing. That can\'t be quite long.</string>
<string name="add_public_comment">Add a public comment</string>
<string name="send_comment">Send comment</string>
<!-- end languages -->