Allow to upload media to stories

This commit is contained in:
tom79 2020-01-19 15:10:49 +01:00
parent 235cea3d0f
commit 36a9fa4932
7 changed files with 203 additions and 108 deletions

View File

@ -541,7 +541,7 @@ public abstract class BaseMainActivity extends BaseActivity
TabLayout.Tab pfTabHome = tabLayout.newTab(); TabLayout.Tab pfTabHome = tabLayout.newTab();
TabLayout.Tab pfTabLocal = tabLayout.newTab(); TabLayout.Tab pfTabLocal = tabLayout.newTab();
TabLayout.Tab pfTabNotification = tabLayout.newTab(); TabLayout.Tab pfTabNotification = tabLayout.newTab();
TabLayout.Tab pfStories = tabLayout.newTab(); // TabLayout.Tab pfStories = tabLayout.newTab();
//TabLayout.Tab pfTabDiscover = tabLayout.newTab(); //TabLayout.Tab pfTabDiscover = tabLayout.newTab();
@ -552,7 +552,7 @@ public abstract class BaseMainActivity extends BaseActivity
pfTabHome.setCustomView(R.layout.tab_badge); pfTabHome.setCustomView(R.layout.tab_badge);
pfTabLocal.setCustomView(R.layout.tab_badge); pfTabLocal.setCustomView(R.layout.tab_badge);
pfTabNotification.setCustomView(R.layout.tab_badge); pfTabNotification.setCustomView(R.layout.tab_badge);
pfStories.setCustomView(R.layout.tab_badge); //pfStories.setCustomView(R.layout.tab_badge);
//pfTabDiscover.setCustomView(R.layout.tab_badge); //pfTabDiscover.setCustomView(R.layout.tab_badge);
@ -575,21 +575,21 @@ public abstract class BaseMainActivity extends BaseActivity
ImageView iconDiscover = pfTabDiscover.getCustomView().findViewById(R.id.tab_icon); ImageView iconDiscover = pfTabDiscover.getCustomView().findViewById(R.id.tab_icon);
iconDiscover.setImageResource(R.drawable.ic_people);*/ iconDiscover.setImageResource(R.drawable.ic_people);*/
@SuppressWarnings("ConstantConditions") @SuppressLint("CutPasteId") /*@SuppressWarnings("ConstantConditions") @SuppressLint("CutPasteId")
ImageView iconStories = pfStories.getCustomView().findViewById(R.id.tab_icon); ImageView iconStories = pfStories.getCustomView().findViewById(R.id.tab_icon);
iconStories.setImageResource(R.drawable.ic_story); iconStories.setImageResource(R.drawable.ic_story);*/
iconHome.setContentDescription(getString(R.string.home_menu)); iconHome.setContentDescription(getString(R.string.home_menu));
// iconDiscover.setContentDescription(getString(R.string.overview)); // iconDiscover.setContentDescription(getString(R.string.overview));
iconLocal.setContentDescription(getString(R.string.local)); iconLocal.setContentDescription(getString(R.string.local));
iconNotif.setContentDescription(getString(R.string.notifications)); iconNotif.setContentDescription(getString(R.string.notifications));
iconStories.setContentDescription(getString(R.string.stories)); //iconStories.setContentDescription(getString(R.string.stories));
tabLayout.addTab(pfTabHome); tabLayout.addTab(pfTabHome);
tabLayout.addTab(pfTabLocal); tabLayout.addTab(pfTabLocal);
tabLayout.addTab(pfTabNotification); tabLayout.addTab(pfTabNotification);
tabLayout.addTab(pfStories); // tabLayout.addTab(pfStories);
// tabLayout.addTab(pfTabDiscover); // tabLayout.addTab(pfTabDiscover);
tabLayout.setTabMode(TabLayout.MODE_FIXED); tabLayout.setTabMode(TabLayout.MODE_FIXED);
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL); tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
@ -2566,12 +2566,12 @@ public abstract class BaseMainActivity extends BaseActivity
bundle.putSerializable("type", DisplayNotificationsFragment.Type.ALL); bundle.putSerializable("type", DisplayNotificationsFragment.Type.ALL);
fragment.setArguments(bundle); fragment.setArguments(bundle);
return fragment; return fragment;
}else if (position == 3) { }/*else if (position == 3) {
DisplayStoriesFragment fragment = new DisplayStoriesFragment(); DisplayStoriesFragment fragment = new DisplayStoriesFragment();
bundle.putSerializable("type", RetrieveStoriesAsyncTask.type.ME); bundle.putSerializable("type", RetrieveStoriesAsyncTask.type.ME);
fragment.setArguments(bundle); fragment.setArguments(bundle);
return fragment; return fragment;
} }*/
/*else if( position == 3) { /*else if( position == 3) {
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.PF_DISCOVER); bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.PF_DISCOVER);
}*/ }*/

View File

@ -60,6 +60,7 @@ import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.TimePicker; import android.widget.TimePicker;
import android.widget.Toast; import android.widget.Toast;
@ -89,6 +90,7 @@ import net.gotev.uploadservice.UploadServiceSingleBroadcastReceiver;
import net.gotev.uploadservice.UploadStatusDelegate; import net.gotev.uploadservice.UploadStatusDelegate;
import org.apache.poi.util.IOUtils; import org.apache.poi.util.IOUtils;
import org.jetbrains.annotations.NotNull;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@ -207,6 +209,8 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
private LinearLayout pickup_picture; private LinearLayout pickup_picture;
private SliderView imageSlider; private SliderView imageSlider;
private SliderAdapter sliderAdapter; private SliderAdapter sliderAdapter;
private CheckBox pixelfed_story;
private BroadcastReceiver imageReceiver = new BroadcastReceiver() { private BroadcastReceiver imageReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
@ -219,7 +223,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
private BroadcastReceiver add_new_media = new BroadcastReceiver() { private BroadcastReceiver add_new_media = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
pixelfed_story.setEnabled(true);
JSONObject response = null; JSONObject response = null;
ArrayList<String> successfullyUploadedFiles = null; ArrayList<String> successfullyUploadedFiles = null;
try { try {
@ -432,7 +436,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
return textw; return textw;
} }
static private void upload(Activity activity, Uri inUri, String fname, UploadServiceSingleBroadcastReceiver uploadReceiver) { static private void upload(Activity activity, boolean pixelfedStory, Uri inUri, String fname, UploadServiceSingleBroadcastReceiver uploadReceiver) {
String uploadId = UUID.randomUUID().toString(); String uploadId = UUID.randomUUID().toString();
if (uploadReceiver != null) { if (uploadReceiver != null) {
uploadReceiver.setUploadID(uploadId); uploadReceiver.setUploadID(uploadId);
@ -480,6 +484,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
IOUtils.closeQuietly(tempOut); IOUtils.closeQuietly(tempOut);
} }
try { try {
final String fileName = FileNameCleaner.cleanFileName(fname); final String fileName = FileNameCleaner.cleanFileName(fname);
SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
@ -487,6 +492,9 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null); String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
int maxUploadRetryTimes = sharedpreferences.getInt(Helper.MAX_UPLOAD_IMG_RETRY_TIMES, 3); int maxUploadRetryTimes = sharedpreferences.getInt(Helper.MAX_UPLOAD_IMG_RETRY_TIMES, 3);
String url = scheme + "://" + Helper.getLiveInstance(activity) + "/api/v1/media"; String url = scheme + "://" + Helper.getLiveInstance(activity) + "/api/v1/media";
if( pixelfedStory) {
url = scheme + "://" + Helper.getLiveInstance(activity) + "/api/stories/v1/add";
}
UploadNotificationConfig uploadConfig = new UploadNotificationConfig(); UploadNotificationConfig uploadConfig = new UploadNotificationConfig();
uploadConfig uploadConfig
.setClearOnActionForAllStatuses(true); .setClearOnActionForAllStatuses(true);
@ -496,13 +504,14 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
request.addHeader("Authorization", "Bearer " + token); request.addHeader("Authorization", "Bearer " + token);
request.setNotificationConfig(uploadConfig); request.setNotificationConfig(uploadConfig);
request.addFileToUpload(uri.toString().replace("file://", ""), "file"); request.addFileToUpload(uri.toString().replace("file://", ""), "file");
request.addParameter("filename", fileName).setMaxRetries(maxUploadRetryTimes) if( !pixelfedStory) {
.startUpload(); request.addParameter("filename", fileName).setMaxRetries(maxUploadRetryTimes);
} catch (MalformedURLException e) { }
e.printStackTrace(); request.startUpload();
} catch (FileNotFoundException e) { } catch (MalformedURLException | FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
public static int countLength(UpdateAccountInfoAsyncTask.SOCIAL social, MastalabAutoCompleteTextView toot_content) { public static int countLength(UpdateAccountInfoAsyncTask.SOCIAL social, MastalabAutoCompleteTextView toot_content) {
@ -634,14 +643,14 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
toot_content = findViewById(R.id.toot_content); toot_content = findViewById(R.id.toot_content);
int newInputType = toot_content.getInputType() & (toot_content.getInputType() ^ InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE); int newInputType = toot_content.getInputType() & (toot_content.getInputType() ^ InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
toot_content.setInputType(newInputType); toot_content.setInputType(newInputType);
ScrollView composer_container = findViewById(R.id.composer_container);
pixelfed_story = findViewById(R.id.pixelfed_story);
//There is no media the button is hidden //There is no media the button is hidden
upload_media.setVisibility(View.INVISIBLE); upload_media.setVisibility(View.INVISIBLE);
toot_sensitive = findViewById(R.id.toot_sensitive); toot_sensitive = findViewById(R.id.toot_sensitive);
LinearLayout drawer_layout = findViewById(R.id.drawer_layout); LinearLayout drawer_layout = findViewById(R.id.drawer_layout);
ImageButton toot_emoji = findViewById(R.id.toot_emoji); ImageButton toot_emoji = findViewById(R.id.toot_emoji);
LinearLayout bottom_bar_tooting = findViewById(R.id.bottom_bar_tooting);
isScheduled = false; isScheduled = false;
if (sharedpreferences.getBoolean(Helper.SET_DISPLAY_EMOJI, true)) { if (sharedpreferences.getBoolean(Helper.SET_DISPLAY_EMOJI, true)) {
final EmojiPopup emojiPopup = EmojiPopup.Builder.fromRootView(drawer_layout).build(toot_content); final EmojiPopup emojiPopup = EmojiPopup.Builder.fromRootView(drawer_layout).build(toot_content);
@ -655,7 +664,18 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
} else { } else {
toot_emoji.setVisibility(View.GONE); toot_emoji.setVisibility(View.GONE);
} }
TextView indication_story = findViewById(R.id.indication_story);
pixelfed_story.setOnCheckedChangeListener((buttonView, isChecked) -> {
if( isChecked){
composer_container.setVisibility(View.GONE);
indication_story.setVisibility(View.VISIBLE);
bottom_bar_tooting.setVisibility(View.GONE);
}else{
composer_container.setVisibility(View.VISIBLE);
indication_story.setVisibility(View.GONE);
bottom_bar_tooting.setVisibility(View.VISIBLE);
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
@ -797,9 +817,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
startActivityForResult(intent, PICK_IMAGE); startActivityForResult(intent, PICK_IMAGE);
} else { } else {
intent.setType("image/* video/* audio/mpeg audio/opus audio/flac audio/wav audio/ogg"); intent.setType("image/* video/* audio/mpeg audio/opus audio/flac audio/wav audio/ogg");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
}
Intent pickIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); Intent pickIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
Intent chooserIntent = Intent.createChooser(intent, getString(R.string.toot_select_image)); Intent chooserIntent = Intent.createChooser(intent, getString(R.string.toot_select_image));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{pickIntent}); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{pickIntent});
@ -831,9 +849,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
startActivityForResult(intent, PICK_IMAGE); startActivityForResult(intent, PICK_IMAGE);
} else { } else {
intent.setType("image/* video/* audio/mpeg audio/opus audio/flac audio/wav audio/ogg"); intent.setType("image/* video/* audio/mpeg audio/opus audio/flac audio/wav audio/ogg");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
}
Intent pickIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); Intent pickIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
Intent chooserIntent = Intent.createChooser(intent, getString(R.string.toot_select_image)); Intent chooserIntent = Intent.createChooser(intent, getString(R.string.toot_select_image));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{pickIntent}); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{pickIntent});
@ -871,40 +887,44 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
} }
private void addNewMedia(JSONObject response, ArrayList<String> successfullyUploadedFiles) { private void addNewMedia(JSONObject response, ArrayList<String> successfullyUploadedFiles) {
if( !pixelfed_story.isChecked()) {
Attachment attachment; Attachment attachment;
attachment = API.parseAttachmentResponse(response); attachment = API.parseAttachmentResponse(response);
boolean alreadyAdded = false; boolean alreadyAdded = false;
int index = 0; int index = 0;
for (Attachment attach_ : attachments) { for (Attachment attach_ : attachments) {
if (attach_.getId().equals(attachment.getId())) { if (attach_.getId().equals(attachment.getId())) {
alreadyAdded = true; alreadyAdded = true;
break; break;
}
index++;
} }
index++; if (attachment.getPreview_url().contains("no-preview.png") && successfullyUploadedFiles != null && successfullyUploadedFiles.size() > 0) {
} attachment.setPreview_url(successfullyUploadedFiles.get(0));
if (attachment.getPreview_url().contains("no-preview.png") && successfullyUploadedFiles != null && successfullyUploadedFiles.size() > 0) { }
attachment.setPreview_url(successfullyUploadedFiles.get(0)); if (!alreadyAdded) {
} attachments.add(attachment);
if (!alreadyAdded) { sliderAdapter.notifyDataSetChanged();
attachments.add(attachment); imageSlider.setVisibility(View.VISIBLE);
sliderAdapter.notifyDataSetChanged(); pickup_picture.setVisibility(View.GONE);
imageSlider.setVisibility(View.VISIBLE); upload_media.setVisibility(View.VISIBLE);
pickup_picture.setVisibility(View.GONE); if (attachments.size() < max_media_count)
upload_media.setVisibility(View.VISIBLE); upload_media.setEnabled(true);
if (attachments.size() < max_media_count) toot_it.setEnabled(true);
upload_media.setEnabled(true); toot_sensitive.setVisibility(View.VISIBLE);
toot_it.setEnabled(true); if (account.isSensitive()) {
toot_sensitive.setVisibility(View.VISIBLE); toot_sensitive.setChecked(true);
if (account.isSensitive()) { }
toot_sensitive.setChecked(true); imageSlider.setCurrentPagePosition(imageSlider.getChildCount());
} else {
if (attachments.size() > index && attachment.getDescription() != null) {
attachments.get(index).setDescription(attachment.getDescription());
}
} }
imageSlider.setCurrentPagePosition(imageSlider.getChildCount());
} else { } else {
if (attachments.size() > index && attachment.getDescription() != null) { Toasty.success(getApplicationContext(), getString(R.string.added_to_story), Toast.LENGTH_LONG).show();
attachments.get(index).setDescription(attachment.getDescription());
}
} }
} }
@Override @Override
@ -1058,11 +1078,12 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
} }
private void prepareUpload(Activity activity, Uri uri, String filename, UploadServiceSingleBroadcastReceiver uploadReceiver) { private void prepareUpload(Activity activity, Uri uri, String filename, UploadServiceSingleBroadcastReceiver uploadReceiver) {
pixelfed_story.setEnabled(false);
if (uploadReceiver == null) { if (uploadReceiver == null) {
uploadReceiver = new UploadServiceSingleBroadcastReceiver(PixelfedComposeActivity.this); uploadReceiver = new UploadServiceSingleBroadcastReceiver(PixelfedComposeActivity.this);
uploadReceiver.register(this); uploadReceiver.register(this);
} }
new asyncPicture(activity, social, uri, filename, uploadReceiver).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new asyncPicture(activity, pixelfed_story.isChecked(), uri, filename, uploadReceiver).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} }
@Override @Override
@ -1091,11 +1112,13 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
} }
upload_media.setEnabled(true); upload_media.setEnabled(true);
toot_it.setEnabled(true); toot_it.setEnabled(true);
pixelfed_story.setEnabled(true);
} }
@Override @Override
public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) { public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) {
JSONObject response = null; JSONObject response = null;
pixelfed_story.setEnabled(true);
try { try {
response = new JSONObject(serverResponse.getBodyAsString()); response = new JSONObject(serverResponse.getBodyAsString());
} catch (JSONException e) { } catch (JSONException e) {
@ -1107,6 +1130,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
@Override @Override
public void onCancelled(Context context, UploadInfo uploadInfo) { public void onCancelled(Context context, UploadInfo uploadInfo) {
// your code here // your code here
pixelfed_story.setEnabled(true);
} }
@ -1128,8 +1152,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(@NotNull MenuItem item) {
final SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
int style; int style;
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
@ -1269,8 +1292,6 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
} }
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
String tootContent = toot_content.getText().toString().trim(); String tootContent = toot_content.getText().toString().trim();
Status toot = new Status(); Status toot = new Status();
@ -1334,19 +1355,16 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
} }
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(@NotNull Menu menu) {
getMenuInflater().inflate(R.menu.main_compose_pixelfed, menu); getMenuInflater().inflate(R.menu.main_compose_pixelfed, menu);
if (restored != -1) { if (restored != -1) {
MenuItem itemRestore = menu.findItem(R.id.action_restore); MenuItem itemRestore = menu.findItem(R.id.action_restore);
if (itemRestore != null) if (itemRestore != null)
itemRestore.setVisible(false); itemRestore.setVisible(false);
MenuItem itemSchedule = menu.findItem(R.id.action_schedule); MenuItem itemSchedule = menu.findItem(R.id.action_schedule);
if (restoredScheduled) if (restoredScheduled || pixelfed_story.isChecked())
itemSchedule.setVisible(false); itemSchedule.setVisible(false);
} }
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
return true; return true;
} }
@ -1359,7 +1377,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
String filename = FileNameCleaner.cleanFileName(url); String filename = FileNameCleaner.cleanFileName(url);
upload_media.setEnabled(false); upload_media.setEnabled(false);
toot_it.setEnabled(false); toot_it.setEnabled(false);
upload(PixelfedComposeActivity.this, uri, filename, uploadReceiver); upload(PixelfedComposeActivity.this, pixelfed_story.isChecked(), uri, filename, uploadReceiver);
} }
} }
@ -2003,13 +2021,14 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
UploadServiceSingleBroadcastReceiver uploadReceiver; UploadServiceSingleBroadcastReceiver uploadReceiver;
String filename; String filename;
UpdateAccountInfoAsyncTask.SOCIAL social; UpdateAccountInfoAsyncTask.SOCIAL social;
boolean pixelfedStory;
asyncPicture(Activity activity, UpdateAccountInfoAsyncTask.SOCIAL social, Uri uri, String filename, UploadServiceSingleBroadcastReceiver uploadReceiver) { asyncPicture(Activity activity, boolean pixelfedStory, Uri uri, String filename, UploadServiceSingleBroadcastReceiver uploadReceiver) {
this.activityWeakReference = new WeakReference<>(activity); this.activityWeakReference = new WeakReference<>(activity);
this.uriFile = uri; this.uriFile = uri;
this.uploadReceiver = uploadReceiver; this.uploadReceiver = uploadReceiver;
this.filename = filename; this.filename = filename;
this.social = social; this.pixelfedStory = pixelfedStory;
} }
@Override @Override
@ -2047,7 +2066,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
filename = Helper.getFileName(this.activityWeakReference.get(), uriFile); filename = Helper.getFileName(this.activityWeakReference.get(), uriFile);
} }
filesMap.put(filename, uriFile); filesMap.put(filename, uriFile);
upload(activityWeakReference.get(), uriFile, filename, uploadReceiver); upload(activityWeakReference.get(), pixelfedStory, uriFile, filename, uploadReceiver);
} }
} }
} }

View File

@ -24,17 +24,6 @@ import android.os.Parcelable;
public class Attachment implements Parcelable { public class Attachment implements Parcelable {
public static final Creator<Attachment> CREATOR = new Creator<Attachment>() {
@Override
public Attachment createFromParcel(Parcel in) {
return new Attachment(in);
}
@Override
public Attachment[] newArray(int size) {
return new Attachment[size];
}
};
private String id; private String id;
private String type; private String type;
private String url; private String url;
@ -43,16 +32,7 @@ public class Attachment implements Parcelable {
private String meta; private String meta;
private String text_url; private String text_url;
private String description; private String description;
private String local_path;
public Attachment(Parcel in) {
id = in.readString();
type = in.readString();
url = in.readString();
remote_url = in.readString();
preview_url = in.readString();
text_url = in.readString();
description = in.readString();
}
public Attachment() { public Attachment() {
@ -106,22 +86,6 @@ public class Attachment implements Parcelable {
this.text_url = text_url; this.text_url = text_url;
} }
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(id);
dest.writeString(type);
dest.writeString(url);
dest.writeString(remote_url);
dest.writeString(preview_url);
dest.writeString(text_url);
dest.writeString(description);
}
public String getDescription() { public String getDescription() {
return description; return description;
} }
@ -137,4 +101,54 @@ public class Attachment implements Parcelable {
public void setMeta(String meta) { public void setMeta(String meta) {
this.meta = meta; this.meta = meta;
} }
public String getLocal_path() {
return local_path;
}
public void setLocal_path(String local_path) {
this.local_path = local_path;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.id);
dest.writeString(this.type);
dest.writeString(this.url);
dest.writeString(this.remote_url);
dest.writeString(this.preview_url);
dest.writeString(this.meta);
dest.writeString(this.text_url);
dest.writeString(this.description);
dest.writeString(this.local_path);
}
protected Attachment(Parcel in) {
this.id = in.readString();
this.type = in.readString();
this.url = in.readString();
this.remote_url = in.readString();
this.preview_url = in.readString();
this.meta = in.readString();
this.text_url = in.readString();
this.description = in.readString();
this.local_path = in.readString();
}
public static final Creator<Attachment> CREATOR = new Creator<Attachment>() {
@Override
public Attachment createFromParcel(Parcel source) {
return new Attachment(source);
}
@Override
public Attachment[] newArray(int size) {
return new Attachment[size];
}
};
} }

View File

@ -20,7 +20,6 @@ import android.content.SharedPreferences;
import android.os.Build; import android.os.Build;
import android.text.Html; import android.text.Html;
import android.text.SpannableString; import android.text.SpannableString;
import android.util.Log;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;

View File

@ -4,6 +4,9 @@ import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@ -21,9 +24,12 @@ import app.fedilab.android.R;
import app.fedilab.android.activities.MainActivity; import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask; import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask;
import app.fedilab.android.client.Entities.Account; import app.fedilab.android.client.Entities.Account;
import app.fedilab.android.client.Entities.Attachment;
import app.fedilab.android.client.Entities.Error; import app.fedilab.android.client.Entities.Error;
import app.fedilab.android.client.Entities.PixelFedStory; import app.fedilab.android.client.Entities.PixelFedStory;
import app.fedilab.android.client.Entities.PixelFedStoryItem; import app.fedilab.android.client.Entities.PixelFedStoryItem;
import app.fedilab.android.client.Entities.PollOptions;
import app.fedilab.android.client.Entities.Status;
import app.fedilab.android.helper.Helper; import app.fedilab.android.helper.Helper;
import app.fedilab.android.sqlite.AccountDAO; import app.fedilab.android.sqlite.AccountDAO;
import app.fedilab.android.sqlite.Sqlite; import app.fedilab.android.sqlite.Sqlite;
@ -128,6 +134,41 @@ public class PixelfedAPI {
} }
/**
* Posts a story
*
* @param status Status object related to the status
* @return APIResponse
*/
public APIResponse postStory(Status status) {
JsonObject jsonObject = new JsonObject();
if (status.getMedia_attachments() != null && status.getMedia_attachments().size() > 0) {
JsonArray mediaArray = new JsonArray();
for (Attachment attachment : status.getMedia_attachments())
mediaArray.add(attachment.getId());
jsonObject.add("media_ids", mediaArray);
}
ArrayList<PixelFedStory> statuses = new ArrayList<>();
try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.postJson(getAbsoluteUrl("/add"), 30, jsonObject, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
PixelFedStory statusreturned = parseStory(new JSONObject(response));
statuses.add(statusreturned);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
e.printStackTrace();
}
apiResponse.setPixelFedStories(statuses);
return apiResponse;
}
/** /**
* Retrieves an item from its ID * Retrieves an item from its ID
* *
@ -280,7 +321,7 @@ public class PixelfedAPI {
* @param statusCode int code * @param statusCode int code
* @param error Throwable error * @param error Throwable error
*/ */
private void setError(int statusCode, Throwable error) { public void setError(int statusCode, Throwable error) {
APIError = new Error(); APIError = new Error();
APIError.setStatusCode(statusCode); APIError.setStatusCode(statusCode);
String message = statusCode + " - " + error.getMessage(); String message = statusCode + " - " + error.getMessage();
@ -313,6 +354,8 @@ public class PixelfedAPI {
} }
public Error getError() { public Error getError() {
return APIError; return APIError;
} }

View File

@ -93,6 +93,21 @@
android:text="@string/upload_media" /> android:text="@string/upload_media" />
</LinearLayout> </LinearLayout>
<CheckBox
android:id="@+id/pixelfed_story"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/pixelfed_story"/>
<TextView
android:visibility="gone"
android:layout_marginTop="10dp"
android:textColor="@color/green"
android:background="@drawable/green_border"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/story_indication"
android:id="@+id/indication_story"/>
<ScrollView <ScrollView
android:id="@+id/composer_container" android:id="@+id/composer_container"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -176,6 +191,7 @@
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/button_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal">
@ -220,6 +236,7 @@
android:text="@string/cw" android:text="@string/cw"
android:textColor="?attr/iconColor" /> android:textColor="?attr/iconColor" />
<TextView <TextView
android:id="@+id/toot_space_left" android:id="@+id/toot_space_left"
android:layout_width="0dp" android:layout_width="0dp"

View File

@ -1215,4 +1215,7 @@
<string name="verified_by">Verified by %1$s (%2$s)</string> <string name="verified_by">Verified by %1$s (%2$s)</string>
<string name="remove_notification">Delete the notification</string> <string name="remove_notification">Delete the notification</string>
<string name="display_more_options">Display more options</string> <string name="display_more_options">Display more options</string>
<string name="pixelfed_story">It is a Pixelfed story</string>
<string name="story_indication">Upload a media, it will be automatically added to your Pixelfed story.</string>
<string name="added_to_story">Media successfully added to your story!</string>
</resources> </resources>