Add contact issue #668

This commit is contained in:
stom79 2019-01-23 19:23:26 +01:00
parent 256d3b5fce
commit da2602c298
12 changed files with 209 additions and 37 deletions

View File

@ -2515,30 +2515,28 @@ public abstract class BaseMainActivity extends BaseActivity
itemMediaOnly.setChecked(mediaOnly[0]);
itemShowNSFW.setChecked(showNSFW[0]);
List<TagTimeline> finalTagTimelines = tagTimelines;
popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
@Override
public void onDismiss(PopupMenu menu) {
if(changes[0]) {
FragmentTransaction fragTransaction = getSupportFragmentManager().beginTransaction();
String tag;
if (finalTagTimelines == null || finalTagTimelines.size() == 0)
tag = tabLayout.getTabAt(position).getText().toString();
else
if (finalTagTimelines != null && finalTagTimelines.size() > 0)
popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
@Override
public void onDismiss(PopupMenu menu) {
if(changes[0]) {
FragmentTransaction fragTransaction = getSupportFragmentManager().beginTransaction();
String tag;
tag = finalTagTimelines.get(0).getName();
fragTransaction.detach(tagFragment.get(tag));
Bundle bundle = new Bundle();
if( mediaOnly[0])
bundle.putString("instanceType","ART");
else
bundle.putString("instanceType","MASTODON");
bundle.putString("tag", tag);
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.TAG);
tagFragment.get(tag).setArguments(bundle);
fragTransaction.attach(tagFragment.get(tag));
fragTransaction.commit();
fragTransaction.detach(tagFragment.get(tag));
Bundle bundle = new Bundle();
if( mediaOnly[0])
bundle.putString("instanceType","ART");
else
bundle.putString("instanceType","MASTODON");
bundle.putString("tag", tag);
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.TAG);
tagFragment.get(tag).setArguments(bundle);
fragTransaction.attach(tagFragment.get(tag));
fragTransaction.commit();
}
}
}
});
});
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {

View File

@ -47,9 +47,11 @@ import android.text.Html;
import android.text.InputFilter;
import android.text.InputType;
import android.text.TextWatcher;
import android.util.Log;
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.ViewTreeObserver;
@ -66,6 +68,7 @@ import android.widget.HorizontalScrollView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
@ -204,6 +207,11 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
private int style;
private StoredStatus scheduledstatus;
private boolean isScheduled;
private List<Boolean> checkedValues;
private List<Account> contacts;
private ListView lv_accounts_search;
private AccountsReplyAdapter contactAdapter;
private RelativeLayout loader;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -265,7 +273,8 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
currentToId = -1;
restoredScheduled = false;
checkedValues = new ArrayList<>();
contacts = new ArrayList<>();
toot_it = findViewById(R.id.toot_it);
Button toot_cw = findViewById(R.id.toot_cw);
toot_space_left = findViewById(R.id.toot_space_left);
@ -787,6 +796,8 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
}
}
private class asyncPicture extends AsyncTask<Void, Void, Void> {
ByteArrayInputStream bs;
@ -871,6 +882,17 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
@Override
public boolean onOptionsItemSelected(MenuItem item) {
final SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
int style;
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
} else if (theme == Helper.THEME_BLACK){
style = R.style.DialogBlack;
}else {
style = R.style.Dialog;
}
switch (item.getItemId()) {
case android.R.id.home:
finish();
@ -905,8 +927,6 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
return true;
case R.id.action_translate:
final CountryPicker picker = CountryPicker.newInstance(getString(R.string.which_language)); // dialog title
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
final int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if( theme == Helper.THEME_LIGHT){
picker.setStyle(R.style.AppTheme, R.style.AlertDialog);
}else {
@ -1098,6 +1118,62 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
return true;
case R.id.action_photo_camera:
dispatchTakePictureIntent();
return true;
case R.id.action_contacts:
AlertDialog.Builder builderSingle = new AlertDialog.Builder(TootActivity.this, style);
builderSingle.setTitle(getString(R.string.select_accounts));
LayoutInflater inflater = getLayoutInflater();
@SuppressLint("InflateParams") View dialogView = inflater.inflate(R.layout.popup_contact, null);
loader = dialogView.findViewById(R.id.loader);
EditText search_account = dialogView.findViewById(R.id.search_account);
lv_accounts_search = dialogView.findViewById(R.id.lv_accounts_search);
loader.setVisibility(View.VISIBLE);
new RetrieveSearchAccountsAsyncTask(TootActivity.this, "a", true,TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
search_account.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (count > 0) {
search_account.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_close, 0);
}else{
search_account.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_search, 0);
}
}
@Override
public void afterTextChanged(Editable s) {
if( s != null && s.length() > 0){
new RetrieveSearchAccountsAsyncTask(TootActivity.this, s.toString(), true,TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
});
search_account.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final int DRAWABLE_RIGHT = 2;
if (event.getAction() == MotionEvent.ACTION_UP) {
if (search_account.length() > 0 && event.getRawX() >= (search_account.getRight() - search_account.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
search_account.setText("");
}
}
return false;
}
});
builderSingle.setView(dialogView);
builderSingle.setNegativeButton(R.string.validate, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
toot_content.setSelection(toot_content.getText().length());
}
});
builderSingle.show();
return true;
case R.id.action_microphone:
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
@ -1129,7 +1205,7 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
Toasty.info(getApplicationContext(), getString(R.string.no_draft), Toast.LENGTH_LONG).show();
return true;
}
AlertDialog.Builder builderSingle = new AlertDialog.Builder(TootActivity.this, style);
builderSingle = new AlertDialog.Builder(TootActivity.this, style);
builderSingle.setTitle(getString(R.string.choose_toot));
final DraftsListAdapter draftsListAdapter = new DraftsListAdapter(TootActivity.this, drafts);
final int[] ids = new int[drafts.size()];
@ -1188,8 +1264,8 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
return true;
}
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(TootActivity.this, style);
LayoutInflater inflater = this.getLayoutInflater();
@SuppressLint("InflateParams") View dialogView = inflater.inflate(R.layout.datetime_picker, null);
inflater = this.getLayoutInflater();
dialogView = inflater.inflate(R.layout.datetime_picker, null);
dialogBuilder.setView(dialogView);
final AlertDialog alertDialog = dialogBuilder.create();
@ -1844,6 +1920,23 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
}
}
@Override
public void onRetrieveContact(APIResponse apiResponse) {
if( apiResponse.getError() != null || apiResponse.getAccounts() == null || apiResponse.getAccounts().size() == 0)
return;
if( contacts == null) {
this.contacts = new ArrayList<>();
}
this.contacts = apiResponse.getAccounts();
for(Account account: contacts) {
checkedValues.add(toot_content.getText().toString().contains("@" + account.getAcct()));
Log.v(Helper.TAG,"@" + account.getAcct() + " -> " + toot_content.getText().toString().contains("@" + account.getAcct()));
}
loader.setVisibility(View.GONE);
contactAdapter = new AccountsReplyAdapter(TootActivity.this, contacts, checkedValues);
lv_accounts_search.setAdapter(contactAdapter);
}
@Override
public void onRetrieveEmoji(Status status, boolean fromTranslation) {

View File

@ -35,24 +35,38 @@ public class RetrieveSearchAccountsAsyncTask extends AsyncTask<Void, Void, Void>
private APIResponse apiResponse;
private OnRetrieveSearcAccountshInterface listener;
private WeakReference<Context> contextReference;
private boolean following;
public RetrieveSearchAccountsAsyncTask(Context context, String query, OnRetrieveSearcAccountshInterface onRetrieveSearcAccountshInterface){
this.contextReference = new WeakReference<>(context);
this.query = query;
this.listener = onRetrieveSearcAccountshInterface;
this.following = false;
}
public RetrieveSearchAccountsAsyncTask(Context context, String query, boolean following, OnRetrieveSearcAccountshInterface onRetrieveSearcAccountshInterface){
this.contextReference = new WeakReference<>(context);
this.query = query;
this.listener = onRetrieveSearcAccountshInterface;
this.following = following;
}
@Override
protected Void doInBackground(Void... params) {
API api = new API(this.contextReference.get());
apiResponse = api.searchAccounts(query, 20);
if( !following)
apiResponse = api.searchAccounts(query, 20);
else
apiResponse = new API(contextReference.get()).searchAccounts(query, 20, true);
return null;
}
@Override
protected void onPostExecute(Void result) {
listener.onRetrieveSearchAccounts(apiResponse);
if( !following)
listener.onRetrieveSearchAccounts(apiResponse);
else
listener.onRetrieveContact(apiResponse);
}
}

View File

@ -92,8 +92,13 @@ public class PeertubeAPI {
this.instance = Helper.getLiveInstance(context);
else {
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
Account account = new AccountDAO(context, db).getAccountByID(userId);
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
Account account = new AccountDAO(context, db).getAccountByToken(token);
if( account == null) {
apiResponse = new APIResponse();
APIError = new Error();
return;
}
this.instance = account.getInstance().trim();
}
this.prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);

View File

@ -55,6 +55,18 @@ public class AccountsReplyAdapter extends BaseAdapter{
this.checked = checked;
}
public AccountsReplyAdapter(Context context, List<Account> accounts, List<Boolean> checked){
this.accounts = accounts;
this.context = context;
layoutInflater = LayoutInflater.from(context);
this.checked = new boolean[checked.size()];
int index = 0;
for (Boolean val : checked) {
this.checked[index++] = val;
}
}
@Override
public int getCount() {
return accounts.size();

View File

@ -15,6 +15,7 @@ package fr.gouv.etalab.mastodon.fragments;
* see <http://www.gnu.org/licenses>. */
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
@ -103,7 +104,7 @@ public class DisplayListsFragment extends Fragment implements OnListActionInterf
style = R.style.Dialog;
}
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context, style);
LayoutInflater inflater = getLayoutInflater();
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
@SuppressLint("InflateParams") View dialogView = inflater.inflate(R.layout.add_list, null);
dialogBuilder.setView(dialogView);
final EditText editText = dialogView.findViewById(R.id.add_list);

View File

@ -1682,11 +1682,11 @@ public class Helper {
}
}
FloatingActionMenu actionMenuAcc = actionMenuAccBuilder.attachTo(actionButtonAcc)
.setStartAngle(0)
.setEndAngle(135)
.build();
if( actionButtonAcc != null) {
FloatingActionMenu actionMenuAcc = actionMenuAccBuilder.attachTo(actionButtonAcc)
.setStartAngle(0)
.setEndAngle(135)
.build();
if( accounts.size() > 2){
actionButtonAcc.setFocusableInTouchMode(true);
actionButtonAcc.setFocusable(true);

View File

@ -23,4 +23,5 @@ import fr.gouv.etalab.mastodon.client.APIResponse;
*/
public interface OnRetrieveSearcAccountshInterface {
void onRetrieveSearchAccounts(APIResponse apiResponse);
void onRetrieveContact(APIResponse apiResponse);
}

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="#FFFFFFFF"
android:pathData="M20,0L4,0v2h16L20,0zM4,24h16v-2L4,22v2zM20,4L4,4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2zM12,6.75c1.24,0 2.25,1.01 2.25,2.25s-1.01,2.25 -2.25,2.25S9.75,10.24 9.75,9 10.76,6.75 12,6.75zM17,17L7,17v-1.5c0,-1.67 3.33,-2.5 5,-2.5s5,0.83 5,2.5L17,17z"/>
</vector>

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/search_account"
android:drawableRight="@drawable/ic_search"
android:drawableEnd="@drawable/ic_search"
android:maxLines="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text" />
<RelativeLayout
android:id="@+id/loader"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true" />
</RelativeLayout>
<ListView
android:id="@+id/lv_accounts_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:divider="@null"
/>
</LinearLayout>

View File

@ -16,6 +16,11 @@
android:title="@string/camera"
android:icon="@drawable/ic_photo_camera"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_contacts"
android:title="@string/contact"
android:icon="@drawable/ic_contacts"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_microphone"
android:title="@string/microphone"

View File

@ -841,6 +841,7 @@
<string name="settings_category_label_interface">Interface</string>
<string name="settings_category_label_hiddencontent">Hidden content</string>
<string name="settings_category_label_composing">Composing</string>
<string name="contact">Contacts</string>
<!-- end languages -->