Browse Source

Add image upload icon to dms layout and handle click

legacy
Ammar Githam 4 years ago
parent
commit
68dbf59ef6
  1. 57
      app/src/main/java/awais/instagrabber/activities/DirectMessageThread.java
  2. 10
      app/src/main/res/drawable/ic_image_24.xml
  3. 10
      app/src/main/res/drawable/ic_send_24.xml
  4. 41
      app/src/main/res/layout/activity_dms.xml
  5. 1
      app/src/main/res/values/strings.xml

57
app/src/main/java/awais/instagrabber/activities/DirectMessageThread.java

@ -1,9 +1,12 @@
package awais.instagrabber.activities; package awais.instagrabber.activities;
import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.provider.OpenableColumns;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
@ -13,6 +16,8 @@ import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -36,7 +41,12 @@ import awais.instagrabber.models.enums.UserInboxDirection;
import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.Utils; import awais.instagrabber.utils.Utils;
import static android.view.View.VISIBLE;
public final class DirectMessageThread extends BaseLanguageActivity { public final class DirectMessageThread extends BaseLanguageActivity {
private static final String TAG = "DirectMessageThread";
private static final int PICK_IMAGE = 100;
private DirectItemModel directItemModel; private DirectItemModel directItemModel;
private String threadId; private String threadId;
private String endCursor; private String endCursor;
@ -86,7 +96,8 @@ public final class DirectMessageThread extends BaseLanguageActivity {
dmsBinding.swipeRefreshLayout.setRefreshing(false); dmsBinding.swipeRefreshLayout.setRefreshing(false);
} }
}; };
private final View.OnClickListener newCommentListener = v -> {
private final View.OnClickListener clickListener = v -> {
if (v == dmsBinding.commentSend) {
if (Utils.isEmpty(dmsBinding.commentText.getText().toString())) { if (Utils.isEmpty(dmsBinding.commentText.getText().toString())) {
Toast.makeText(getApplicationContext(), R.string.comment_send_empty_comment, Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), R.string.comment_send_empty_comment, Toast.LENGTH_SHORT).show();
return; return;
@ -104,6 +115,15 @@ public final class DirectMessageThread extends BaseLanguageActivity {
new UserInboxFetcher(threadId, UserInboxDirection.OLDER, null, fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new UserInboxFetcher(threadId, UserInboxDirection.OLDER, null, fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}); });
action.execute(); action.execute();
return;
}
if (v == dmsBinding.image) {
final Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, getString(R.string.select_picture)), PICK_IMAGE);
}
}; };
@Override @Override
@ -121,9 +141,11 @@ public final class DirectMessageThread extends BaseLanguageActivity {
} }
dmsBinding.swipeRefreshLayout.setEnabled(false); dmsBinding.swipeRefreshLayout.setEnabled(false);
dmsBinding.commentText.setVisibility(View.VISIBLE);
dmsBinding.commentSend.setVisibility(View.VISIBLE);
dmsBinding.commentSend.setOnClickListener(newCommentListener);
dmsBinding.commentText.setVisibility(VISIBLE);
dmsBinding.commentSend.setVisibility(VISIBLE);
dmsBinding.image.setVisibility(VISIBLE);
dmsBinding.commentSend.setOnClickListener(clickListener);
dmsBinding.image.setOnClickListener(clickListener);
final LinearLayoutManager layoutManager = new LinearLayoutManager(this, RecyclerView.VERTICAL, true); final LinearLayoutManager layoutManager = new LinearLayoutManager(this, RecyclerView.VERTICAL, true);
dmsBinding.rvDirectMessages.setLayoutManager(layoutManager); dmsBinding.rvDirectMessages.setLayoutManager(layoutManager);
@ -199,6 +221,33 @@ public final class DirectMessageThread extends BaseLanguageActivity {
new UserInboxFetcher(threadModel.getThreadId(), UserInboxDirection.OLDER, null, fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new UserInboxFetcher(threadModel.getThreadId(), UserInboxDirection.OLDER, null, fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} }
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE && resultCode == Activity.RESULT_OK) {
if (data == null || data.getData() == null) {
Log.w(TAG, "data is null!");
return;
}
Cursor cursor = null;
try {
final Uri uri = data.getData();
cursor = getContentResolver().query(uri, null, null, null, null);
if (cursor != null) {
final int contentLength = cursor.getColumnIndex(OpenableColumns.SIZE);
final InputStream inputStream = getContentResolver().openInputStream(uri);
// TODO Handle image upload
}
} catch (FileNotFoundException e) {
Log.e(TAG, "Error opening InputStream", e);
} finally {
if (cursor != null) {
cursor.close();
}
}
}
}
@Nullable @Nullable
private ProfileModel getUser(final long userId) { private ProfileModel getUser(final long userId) {
if (users != null) { if (users != null) {

10
app/src/main/res/drawable/ic_image_24.xml

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M19,5v14L5,19L5,5h14m0,-2L5,3c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2zM14.14,11.86l-3,3.87L9,13.14 6,17h12l-3.86,-5.14z"/>
</vector>

10
app/src/main/res/drawable/ic_send_24.xml

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

41
app/src/main/res/layout/activity_dms.xml

@ -9,14 +9,13 @@
<include <include
android:id="@+id/toolbar" android:id="@+id/toolbar"
android:layout_weight="1"
layout="@layout/layout_include_toolbar" /> layout="@layout/layout_include_toolbar" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout" android:id="@+id/swipeRefreshLayout"
android:layout_weight="8"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="0dp"
android:layout_weight="8">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvDirectMessages" android:id="@+id/rvDirectMessages"
@ -30,27 +29,49 @@
<EditText <EditText
android:id="@+id/commentText" android:id="@+id/commentText"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="2" android:layout_weight="2"
android:paddingLeft="8dp"
android:gravity="bottom" android:gravity="bottom"
android:hint="@string/dm_hint" android:hint="@string/dm_hint"
android:importantForAutofill="no"
android:inputType="textMultiLine" android:inputType="textMultiLine"
android:maxLength="2200" android:maxLength="2200"
android:maxLines="10" android:maxLines="10"
android:visibility="gone"
android:scrollHorizontally="false" />
android:paddingStart="8dp"
android:paddingLeft="8dp"
android:paddingEnd="4dp"
android:paddingRight="4dp"
android:scrollHorizontally="false"
android:visibility="visible" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="?selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="true"
android:padding="4dp"
android:visibility="visible"
app:srcCompat="@drawable/ic_image_24" />
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/commentSend" android:id="@+id/commentSend"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="?selectableItemBackgroundBorderless" android:background="?selectableItemBackgroundBorderless"
android:clickable="true" android:clickable="true"
android:focusable="true"
android:paddingStart="4dp"
android:paddingLeft="4dp"
android:paddingTop="4dp"
android:paddingEnd="8dp"
android:paddingRight="8dp" android:paddingRight="8dp"
android:visibility="gone"
app:srcCompat="@android:drawable/ic_menu_send" />
android:paddingBottom="4dp"
android:visibility="visible"
app:srcCompat="@drawable/ic_send_24" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

1
app/src/main/res/values/strings.xml

@ -213,4 +213,5 @@
<string name="use_amoled_dark_theme">Use AMOLED mode for Dark theme</string> <string name="use_amoled_dark_theme">Use AMOLED mode for Dark theme</string>
<string name="action_notif">Activity</string> <string name="action_notif">Activity</string>
<string name="license" translatable="false">InstaGrabber\nCopyright (C) 2019 AWAiS\nCopyright (C) 2020 Austin Huang, Ammar Githam\n\nThis 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. See https://www.gnu.org/licenses/.\n\nTHIS SOFTWARE IS PROVIDED BY THE AUTHOR \'\'AS IS\'\' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\nSee project page for third-party attributions.</string> <string name="license" translatable="false">InstaGrabber\nCopyright (C) 2019 AWAiS\nCopyright (C) 2020 Austin Huang, Ammar Githam\n\nThis 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. See https://www.gnu.org/licenses/.\n\nTHIS SOFTWARE IS PROVIDED BY THE AUTHOR \'\'AS IS\'\' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\nSee project page for third-party attributions.</string>
<string name="select_picture">Select Picture</string>
</resources> </resources>
Loading…
Cancel
Save