summaryrefslogtreecommitdiffstats
path: root/app/src/main/java
diff options
context:
space:
mode:
authorstom79 <tschneider.ac@gmail.com>2019-01-07 16:44:19 +0100
committerstom79 <tschneider.ac@gmail.com>2019-01-07 16:44:19 +0100
commit5ee84010df2810ed2ee7b14fc0d094f5d5ec8112 (patch)
treed1c717bda78017fc6f8d8201ae1de00589442434 /app/src/main/java
parente38f4582459c723ec79b784325c13e624cb0c66f (diff)
Finish front-end
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java4
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeUploadActivity.java136
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrievePeertubeChannelsAsyncTask.java69
3 files changed, 207 insertions, 2 deletions
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java
index c0bc31abc..4f1687536 100644
--- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java
+++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java
@@ -1951,6 +1951,10 @@ public abstract class BaseMainActivity extends BaseActivity
Intent intent = new Intent(getApplicationContext(), AboutActivity.class);
startActivity(intent);
return false;
+ } else if( id == R.id.nav_upload) {
+ Intent intent = new Intent(getApplicationContext(), PeertubeUploadActivity.class);
+ startActivity(intent);
+ return false;
} else if( id == R.id.nav_language) {
Intent intent = new Intent(getApplicationContext(), LanguageActivity.class);
startActivity(intent);
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeUploadActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeUploadActivity.java
index 4b3cc00ea..6fe51c872 100644
--- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeUploadActivity.java
+++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeUploadActivity.java
@@ -15,29 +15,56 @@ package fr.gouv.etalab.mastodon.activities;
* see <http://www.gnu.org/licenses>. */
+import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
+import android.database.Cursor;
+import android.net.Uri;
+import android.os.AsyncTask;
+import android.os.Build;
import android.os.Bundle;
+import android.provider.OpenableColumns;
+import android.support.v4.app.ActivityCompat;
+import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
import android.widget.ImageView;
+import android.widget.Spinner;
import android.widget.TextView;
+import android.widget.Toast;
+import java.io.File;
+import java.util.HashMap;
+import java.util.List;
+
+import es.dmoral.toasty.Toasty;
import fr.gouv.etalab.mastodon.R;
+import fr.gouv.etalab.mastodon.asynctasks.RetrievePeertubeChannelsAsyncTask;
+import fr.gouv.etalab.mastodon.client.APIResponse;
+import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.helper.Helper;
+import fr.gouv.etalab.mastodon.interfaces.OnRetrievePeertubeInterface;
import static fr.gouv.etalab.mastodon.helper.Helper.THEME_LIGHT;
-public class PeertubeUploadActivity extends BaseActivity{
+public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePeertubeInterface {
- private final int PICK_IVDEO = 567786;
+ private final int PICK_IVDEO = 52378;
+ private Button set_upload_file, set_upload_submit;
+ private Spinner set_upload_privacy, set_upload_channel;
+ private TextView set_upload_file_name;
+ private HashMap<String, String> channels;
+ private final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 724;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -83,7 +110,14 @@ public class PeertubeUploadActivity extends BaseActivity{
}
setContentView(R.layout.activity_peertube_upload);
+ set_upload_file = findViewById(R.id.set_upload_file);
+ set_upload_file_name = findViewById(R.id.set_upload_file_name);
+ set_upload_channel = findViewById(R.id.set_upload_channel);
+ set_upload_privacy = findViewById(R.id.set_upload_privacy);
+ set_upload_submit = findViewById(R.id.set_upload_submit);
+ new RetrievePeertubeChannelsAsyncTask(PeertubeUploadActivity.this, PeertubeUploadActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
+ channels = new HashMap<>();
}
@@ -92,7 +126,105 @@ public class PeertubeUploadActivity extends BaseActivity{
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IVDEO && resultCode == Activity.RESULT_OK) {
+ if (data == null || data.getData() == null) {
+ Toasty.error(getApplicationContext(),getString(R.string.toot_select_image_error),Toast.LENGTH_LONG).show();
+ return;
+ }
+ set_upload_submit.setEnabled(true);
+
+ Uri uri = data.getData();
+ String uriString = uri.toString();
+ File myFile = new File(uriString);
+ String filename = null;
+ if (uriString.startsWith("content://")) {
+ Cursor cursor = null;
+ try {
+ cursor = getContentResolver().query(uri, null, null, null, null);
+ if (cursor != null && cursor.moveToFirst()) {
+ filename = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
+ }
+ } finally {
+ assert cursor != null;
+ cursor.close();
+ }
+ } else if (uriString.startsWith("file://")) {
+ filename = myFile.getName();
+ }
+ if( filename != null) {
+ set_upload_file_name.setVisibility(View.VISIBLE);
+ set_upload_file_name.setText(filename);
+ }
+
+ }
+ }
+
+ @Override
+ public void onRetrievePeertube(APIResponse apiResponse) {
+ if( apiResponse.getError() != null || apiResponse.getAccounts() == null || apiResponse.getAccounts().size() == 0){
+ if ( apiResponse.getError().getError() != null)
+ Toasty.error(PeertubeUploadActivity.this, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
+ else
+ Toasty.error(PeertubeUploadActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
+ return;
+ }
+ //Populate channels
+ List<Account> accounts = apiResponse.getAccounts();
+ String[] channelName = new String[accounts.size()];
+ int i = 0;
+ for(Account account: accounts){
+ channels.put(account.getUsername(),account.getId());
+ channelName[i] = account.getUsername();
+ i++;
}
+ ArrayAdapter<String> adapterChannel = new ArrayAdapter<>(PeertubeUploadActivity.this,
+ android.R.layout.simple_spinner_dropdown_item, channelName);
+ set_upload_channel.setAdapter(adapterChannel);
+
+ //Populate privacy
+ String[] privacyName = new String[3];
+ privacyName[0] = getString(R.string.v_public);
+ privacyName[1] = getString(R.string.v_unlisted);
+ privacyName[2] = getString(R.string.v_private);
+ ArrayAdapter<String> adapterPrivacy = new ArrayAdapter<>(PeertubeUploadActivity.this,
+ android.R.layout.simple_spinner_dropdown_item, privacyName);
+ set_upload_privacy.setAdapter(adapterPrivacy);
+
+ set_upload_file.setEnabled(true);
+
+ set_upload_file.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ if (ContextCompat.checkSelfPermission(PeertubeUploadActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) !=
+ PackageManager.PERMISSION_GRANTED) {
+ ActivityCompat.requestPermissions(PeertubeUploadActivity.this,
+ new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
+ MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
+ return;
+ }
+ }
+ Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
+ intent.addCategory(Intent.CATEGORY_OPENABLE);
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
+ intent.setType("*/*");
+ String[] mimetypes = {"video/*"};
+ intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
+ startActivityForResult(intent, PICK_IVDEO);
+ }else {
+ intent.setType("video/*");
+ Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
+ Intent chooserIntent = Intent.createChooser(intent, getString(R.string.toot_select_image));
+ chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {pickIntent});
+ startActivityForResult(chooserIntent, PICK_IVDEO);
+ }
+
+ }
+ });
+ }
+
+ @Override
+ public void onRetrievePeertubeComments(APIResponse apiResponse) {
+
}
}
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrievePeertubeChannelsAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrievePeertubeChannelsAsyncTask.java
new file mode 100644
index 000000000..ddfe14d3f
--- /dev/null
+++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrievePeertubeChannelsAsyncTask.java
@@ -0,0 +1,69 @@
+/* Copyright 2019 Thomas Schneider
+ *
+ * This file is a part of Mastalab
+ *
+ * This 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.
+ *
+ * Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
+ * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+ * Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with Mastalab; if not,
+ * see <http://www.gnu.org/licenses>. */
+package fr.gouv.etalab.mastodon.asynctasks;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.database.sqlite.SQLiteDatabase;
+import android.os.AsyncTask;
+
+import java.lang.ref.WeakReference;
+
+import fr.gouv.etalab.mastodon.client.APIResponse;
+import fr.gouv.etalab.mastodon.client.Entities.Account;
+import fr.gouv.etalab.mastodon.client.PeertubeAPI;
+import fr.gouv.etalab.mastodon.helper.Helper;
+import fr.gouv.etalab.mastodon.interfaces.OnRetrievePeertubeInterface;
+import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
+import fr.gouv.etalab.mastodon.sqlite.Sqlite;
+
+
+/**
+ * Created by Thomas on 07/01/2019.
+ * Retrieves peertube Channels
+ */
+
+public class RetrievePeertubeChannelsAsyncTask extends AsyncTask<Void, Void, Void> {
+
+
+
+ private APIResponse apiResponse;
+ private OnRetrievePeertubeInterface listener;
+ private WeakReference<Context> contextReference;
+
+
+
+
+ public RetrievePeertubeChannelsAsyncTask(Context context, OnRetrievePeertubeInterface onRetrievePeertubeInterface){
+ this.contextReference = new WeakReference<>(context);
+ this.listener = onRetrievePeertubeInterface;
+ }
+
+ @Override
+ protected Void doInBackground(Void... params) {
+ PeertubeAPI peertubeAPI = new PeertubeAPI(this.contextReference.get());
+ SQLiteDatabase db = Sqlite.getInstance(contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
+ SharedPreferences sharedpreferences = contextReference.get().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
+ String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
+ Account account = new AccountDAO(contextReference.get(), db).getAccountByToken(token);
+ apiResponse = peertubeAPI.getPeertubeChannel(account.getUsername());
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void result) {
+ listener.onRetrievePeertube(apiResponse);
+ }
+}