Commit c12261d1 authored by Yusuke Iwaki's avatar Yusuke Iwaki

hoge

parent d0cfaf64
package chat.rocket.android.layouthelper.extra_action.upload;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import chat.rocket.android.R;
import chat.rocket.android.layouthelper.extra_action.AbstractExtraActionItem;
......@@ -13,15 +21,77 @@ public abstract class AbstractUploadActionItem extends AbstractExtraActionItem {
@Override
public void handleItemSelectedOnActivity(Activity activity) {
activity.startActivityForResult(getIntentForPickFile(), RC_UPL);
DetailItemInfo[] itemList = getDetailItemList();
if (itemList.length >= 2) {
showSelectionDialog(activity, itemList,
index -> handleDetailItemInfo(activity, itemList[index]));
} else if (itemList.length == 1) {
handleDetailItemInfo(activity, itemList[0]);
}
}
@Override
public void handleItemSelectedOnFragment(Fragment fragment) {
fragment.startActivityForResult(getIntentForPickFile(), RC_UPL);
DetailItemInfo[] itemList = getDetailItemList();
if (itemList.length >= 2) {
showSelectionDialog(fragment.getContext(), itemList,
index -> handleDetailItemInfo(fragment, itemList[index]));
} else if (itemList.length == 1) {
handleDetailItemInfo(fragment, itemList[0]);
}
}
private void handleDetailItemInfo(Activity activity, DetailItemInfo info) {
if (info != null) {
activity.startActivityForResult(info.getIntent(), info.getReturnCode());
}
}
private void handleDetailItemInfo(Fragment fragment, DetailItemInfo info) {
if (info != null) {
fragment.startActivityForResult(info.getIntent(), info.getReturnCode());
}
}
private interface OnSelectedCallback {
void onSelected(int index);
}
protected abstract Intent getIntentForPickFile();
private void showSelectionDialog(Context context, DetailItemInfo[] itemList,
OnSelectedCallback callback) {
ArrayAdapter<DetailItemInfo> adapter = new ArrayAdapter<DetailItemInfo>(context,
android.R.layout.simple_list_item_1,
android.R.id.text1,
itemList) {
@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView text = (TextView) super.getView(position, convertView, parent);
text.setText(itemList[position].getCaption());
return text;
}
};
// TODO: BottomSheet...
new AlertDialog.Builder(context, R.style.AppTheme_Dialog)
.setAdapter(adapter, (dialogInterface, index) -> callback.onSelected(index))
.show();
}
protected abstract DetailItemInfo[] getDetailItemList();
protected interface DetailItemInfo {
Intent getIntent();
@StringRes int getCaption();
/**
* code used for param of startActivityForResult.
*/
int getReturnCode();
}
@Override
public int getBackgroundTint() {
......
package chat.rocket.android.layouthelper.extra_action.upload;
import android.content.Intent;
import android.provider.MediaStore;
import chat.rocket.android.R;
......@@ -12,11 +13,45 @@ public class AudioUploadActionItem extends AbstractUploadActionItem {
}
@Override
protected Intent getIntentForPickFile() {
Intent intent = new Intent();
intent.setType("audio/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
return Intent.createChooser(intent, "Select Audio to Upload");
protected DetailItemInfo[] getDetailItemList() {
return new DetailItemInfo[] {
new DetailItemInfo() {
@Override
public Intent getIntent() {
Intent intent = new Intent();
intent.setType("audio/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
return Intent.createChooser(intent, "Select Audio to Upload");
}
@Override
public int getCaption() {
return R.string.title_pick_file;
}
@Override
public int getReturnCode() {
return RC_UPL;
}
},
new DetailItemInfo() {
@Override
public Intent getIntent() {
Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
return Intent.createChooser(intent, "Select audio recorder");
}
@Override
public int getCaption() {
return R.string.title_record_audio;
}
@Override
public int getReturnCode() {
return RC_UPL;
}
}
};
}
@Override
......
......@@ -12,11 +12,28 @@ public class ImageUploadActionItem extends AbstractUploadActionItem {
}
@Override
protected Intent getIntentForPickFile() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
return Intent.createChooser(intent, "Select Picture to Upload");
protected DetailItemInfo[] getDetailItemList() {
return new DetailItemInfo[] {
new DetailItemInfo() {
@Override
public Intent getIntent() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
return Intent.createChooser(intent, "Select Picture to Upload");
}
@Override
public int getCaption() {
return R.string.title_pick_file;
}
@Override
public int getReturnCode() {
return RC_UPL;
}
}
};
}
@Override
......
package chat.rocket.android.layouthelper.extra_action.upload;
import android.content.Intent;
import android.provider.MediaStore;
import chat.rocket.android.R;
......@@ -12,11 +13,46 @@ public class VideoUploadActionItem extends AbstractUploadActionItem {
}
@Override
protected Intent getIntentForPickFile() {
Intent intent = new Intent();
intent.setType("video/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
return Intent.createChooser(intent, "Select Video to Upload");
protected DetailItemInfo[] getDetailItemList() {
return new DetailItemInfo[] {
new DetailItemInfo() {
@Override
public Intent getIntent() {
Intent intent = new Intent();
intent.setType("video/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
return Intent.createChooser(intent, "Select Video to Upload");
}
@Override
public int getCaption() {
return R.string.title_pick_file;
}
@Override
public int getReturnCode() {
return RC_UPL;
}
},
new DetailItemInfo() {
@Override
public Intent getIntent() {
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0); //low quality.
return Intent.createChooser(intent, "Select video recorder");
}
@Override
public int getCaption() {
return R.string.title_record_video;
}
@Override
public int getReturnCode() {
return RC_UPL;
}
}
};
}
@Override
......
......@@ -41,6 +41,10 @@
<string name="image_upload_message_spec_title">Attach image</string>
<string name="audio_upload_message_spec_title">Attach audio</string>
<string name="video_upload_message_spec_title">Attach video</string>
<string name="title_pick_file">Select file</string>
<string name="title_take_picture">Take picture</string>
<string name="title_record_audio">Record audio</string>
<string name="title_record_video">Record video</string>
<string name="input_hostname_invalid_server_message">Invalid server version</string>
<string name="connection_error_try_later">There\'s a connection error. Please try later.</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment