1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-22 04:12:08 +01:00

Reworked search dialog to use layout resource and some code cleanup

This commit is contained in:
vanitasvitae 2016-08-27 12:34:08 +02:00
parent 18eeb76079
commit 8ae74d97d4
3 changed files with 50 additions and 44 deletions

View file

@ -323,7 +323,7 @@ public class MainActivity extends AppCompatActivity
// Create the File where the photo should go // Create the File where the photo should go
File photoFile; File photoFile;
try { try {
photoFile = createImageFile(); photoFile = Helpers.createImageFile();
takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath); takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
} catch (IOException ex) { } catch (IOException ex) {
// Error occurred while creating the File // Error occurred while creating the File
@ -429,19 +429,6 @@ public class MainActivity extends AppCompatActivity
onNavigationItemSelected(navView.getMenu().findItem(R.id.nav_stream)); onNavigationItemSelected(navView.getMenu().findItem(R.id.nav_stream));
} }
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("dd-MM-yy_HH-mm", Locale.getDefault()).format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
return File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
}
@Override @Override
protected void onNewIntent(Intent intent) { protected void onNewIntent(Intent intent) {
super.onNewIntent(intent); super.onNewIntent(intent);
@ -568,7 +555,7 @@ public class MainActivity extends AppCompatActivity
if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_STREAM)) { if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_STREAM)) {
setTitle(R.string.nav_stream); setTitle(R.string.nav_stream);
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_POSTS)) { } else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_POSTS)) {
setTitle(R.string.diaspora); //TODO: Extract posts title somehow? setTitle(R.string.diaspora);
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_NOTIFICATIONS)) { } else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_NOTIFICATIONS)) {
setTitle(R.string.notifications); setTitle(R.string.notifications);
} else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_CONVERSATIONS)) { } else if (subUrl.startsWith(DiasporaUrlHelper.SUBURL_CONVERSATIONS)) {
@ -709,50 +696,35 @@ public class MainActivity extends AppCompatActivity
case R.id.action_search: { case R.id.action_search: {
if (WebHelper.isOnline(MainActivity.this)) { if (WebHelper.isOnline(MainActivity.this)) {
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setGravity(Gravity.CENTER_HORIZONTAL);
final EditText input = new EditText(this);
input.setSingleLine(true);
layout.setPadding(50, 0, 50, 0);
input.setHint(R.string.app_hashtag);
layout.addView(input);
final DialogInterface.OnClickListener onSearchAccepted = new DialogInterface.OnClickListener() { View layout = getLayoutInflater().inflate(R.layout.dialog_search__people_tags, null);
public void onClick(DialogInterface dialog, int which) { final EditText input = (EditText) layout.findViewById(R.id.dialog_search__input);
boolean wasClickedOnSearchForPeople = which == DialogInterface.BUTTON_NEGATIVE; final DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() {
@Override
String inputTag = input.getText().toString().trim(); public void onClick(DialogInterface dialogInterface, int which) {
String cleanTag = inputTag.replaceAll(wasClickedOnSearchForPeople ? "\\*" : "\\#", ""); String query = input.getText().toString().trim().replaceAll((which == DialogInterface.BUTTON_NEGATIVE ? "\\*" : "\\#"), "");
// this validate the input data for tagfind if(query.equals("")) {
if (cleanTag == null || cleanTag.equals("")) {
Snackbar.make(contentLayout, R.string.search_alert_bypeople_validate_needsomedata, Snackbar.LENGTH_LONG).show(); Snackbar.make(contentLayout, R.string.search_alert_bypeople_validate_needsomedata, Snackbar.LENGTH_LONG).show();
} else { // User have added a search tag } else {
if (wasClickedOnSearchForPeople) { webView.loadUrl(which == DialogInterface.BUTTON_NEGATIVE ? urls.getSearchPeopleUrl(query) : urls.getSearchTagsUrl(query));
webView.loadUrlNew(urls.getSearchPeopleUrl(cleanTag));
} else {
webView.loadUrlNew(urls.getSearchTagsUrl(cleanTag));
}
} }
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
imm.hideSoftInputFromWindow(input.getWindowToken(), 0); imm.hideSoftInputFromWindow(input.getWindowToken(), 0);
} }
}; };
final AlertDialog dialog = new AlertDialog.Builder(this) final android.support.v7.app.AlertDialog dialog = new android.support.v7.app.AlertDialog.Builder(this)
.setView(layout) .setView(layout).setTitle(R.string.search_alert_title)
.setTitle(R.string.search_alert_title)
.setCancelable(true) .setCancelable(true)
.setPositiveButton(R.string.search_alert_tag, onSearchAccepted) .setPositiveButton(R.string.search_alert_tag, clickListener)
.setNegativeButton(R.string.search_alert_people, onSearchAccepted) .setNegativeButton(R.string.search_alert_people, clickListener)
.create(); .create();
input.setOnEditorActionListener(new TextView.OnEditorActionListener() { input.setOnEditorActionListener(new TextView.OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) { if (actionId == EditorInfo.IME_ACTION_DONE) {
dialog.hide(); dialog.hide();
onSearchAccepted.onClick(null, 0); clickListener.onClick(null, 0);
return true; return true;
} }
return false; return false;

View file

@ -22,9 +22,16 @@ import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Environment;
import com.github.dfa.diaspora_android.R; import com.github.dfa.diaspora_android.R;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class Helpers { public class Helpers {
public static void animateToActivity(Activity from, Class to, boolean finishFromActivity) { public static void animateToActivity(Activity from, Class to, boolean finishFromActivity) {
@ -44,4 +51,17 @@ public class Helpers {
} catch (Exception ignored) { } catch (Exception ignored) {
} }
} }
public static File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("dd-MM-yy_HH-mm", Locale.getDefault()).format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
return File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
}
} }

View file

@ -0,0 +1,14 @@
<?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="match_parent" android:layout_gravity="center_horizontal"
android:paddingStart="@dimen/activity_horizontal_margin_half" android:paddingEnd="@dimen/activity_horizontal_margin_half">
<EditText
android:id="@+id/dialog_search__input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:hint="@string/app_hashtag"
/>
</LinearLayout>