From e38f4582459c723ec79b784325c13e624cb0c66f Mon Sep 17 00:00:00 2001 From: stom79 Date: Mon, 7 Jan 2019 15:27:06 +0100 Subject: [PATCH] Frontend for upload --- app/build.gradle | 2 + .../mastodon/activities/MainApplication.java | 6 +- .../activities/PeertubeUploadActivity.java | 98 +++++++++++++++++ .../etalab/mastodon/client/PeertubeAPI.java | 7 +- .../res/layout/activity_peertube_upload.xml | 100 ++++++++++++++++++ app/src/main/res/values/strings.xml | 1 + 6 files changed, 210 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeUploadActivity.java create mode 100644 app/src/main/res/layout/activity_peertube_upload.xml diff --git a/app/build.gradle b/app/build.gradle index a6944fb6f..392483e32 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -57,6 +57,7 @@ ext.swipebackLibraryVersion = '1.0.2' ext.ratethisappLibraryVersion = '1.2.0' ext.uploadServiceVersion = "3.4.2" ext.torrentstreamVersion = "2.6.1" +ext.uploadServiceVersion = "3.4.2" dependencies { implementation "com.android.support:appcompat-v7:$supportLibraryVersion" @@ -86,5 +87,6 @@ dependencies { implementation 'com.android.support:multidex:1.0.3' implementation 'com.google.android.exoplayer:exoplayer:2.9.3' implementation "com.github.TorrentStream:TorrentStream-Android:$torrentstreamVersion" + implementation "net.gotev:uploadservice:$uploadServiceVersion" playstoreImplementation "io.github.kobakei:ratethisapp:$ratethisappLibraryVersion" } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/MainApplication.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/MainApplication.java index 1dee4a6c6..a491d4b02 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/MainApplication.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/MainApplication.java @@ -24,11 +24,14 @@ import android.support.v4.content.ContextCompat; import com.evernote.android.job.JobManager; import com.franmontiel.localechanger.LocaleChanger; +import net.gotev.uploadservice.UploadService; + import java.util.ArrayList; import java.util.List; import java.util.Locale; import es.dmoral.toasty.Toasty; +import fr.gouv.etalab.mastodon.BuildConfig; import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.jobs.ApplicationJob; @@ -68,7 +71,8 @@ public class MainApplication extends MultiDexApplication { } LocaleChanger.initialize(getApplicationContext(), SUPPORTED_LOCALES); }catch (Exception ignored){ignored.printStackTrace();} - + //Initialize upload service + UploadService.NAMESPACE = BuildConfig.APPLICATION_ID; Toasty.Config.getInstance() .setErrorColor(ContextCompat.getColor(getApplicationContext(), R.color.toasty_background)) .setInfoColor(ContextCompat.getColor(getApplicationContext(), R.color.toasty_background)) 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 new file mode 100644 index 000000000..4b3cc00ea --- /dev/null +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeUploadActivity.java @@ -0,0 +1,98 @@ +package fr.gouv.etalab.mastodon.activities; +/* 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 . */ + + +import android.annotation.SuppressLint; +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +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.ImageView; +import android.widget.TextView; + +import fr.gouv.etalab.mastodon.R; +import fr.gouv.etalab.mastodon.helper.Helper; + +import static fr.gouv.etalab.mastodon.helper.Helper.THEME_LIGHT; + +public class PeertubeUploadActivity extends BaseActivity{ + + + private final int PICK_IVDEO = 567786; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE); + int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); + switch (theme){ + case Helper.THEME_LIGHT: + setTheme(R.style.AppTheme); + break; + case Helper.THEME_DARK: + setTheme(R.style.AppThemeDark); + break; + case Helper.THEME_BLACK: + setTheme(R.style.AppThemeBlack); + break; + default: + setTheme(R.style.AppThemeDark); + } + if( getSupportActionBar() != null) + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + ActionBar actionBar = getSupportActionBar(); + if( actionBar != null ) { + LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + assert inflater != null; + @SuppressLint("InflateParams") View view = inflater.inflate(R.layout.simple_bar, null); + actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); + actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); + ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close); + TextView toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title); + toolbar_close.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + finish(); + } + }); + toolbar_title.setText(R.string.action_about); + if (theme == THEME_LIGHT){ + Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar); + Helper.colorizeToolbar(toolbar, R.color.black, PeertubeUploadActivity.this); + } + } + setContentView(R.layout.activity_peertube_upload); + + + } + + + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (requestCode == PICK_IVDEO && resultCode == Activity.RESULT_OK) { + + } + } +} diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/PeertubeAPI.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/PeertubeAPI.java index 9e0ecf134..a35f9cef4 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/PeertubeAPI.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/PeertubeAPI.java @@ -821,15 +821,16 @@ public class PeertubeAPI { /** - * Retrieves Peertube videos from an instance *synchronously* + * Retrieves Peertube channel from an account *synchronously* + * Peertube channels are dealt like accounts * @return APIResponse */ - public APIResponse getPeertubeChannel(String instance, String name) { + public APIResponse getPeertubeChannel(String name) { List accounts = new ArrayList<>(); try { HttpsConnection httpsConnection = new HttpsConnection(context); - String response = httpsConnection.get(String.format("https://"+instance+"/api/v1/accounts/%s/video-channels", name), 60, null, null); + String response = httpsConnection.get(getAbsoluteUrl(String.format("/accounts/%s/video-channels", name)), 60, null, null); JSONArray jsonArray = new JSONObject(response).getJSONArray("data"); accounts = parseAccountResponsePeertube(context, instance, jsonArray); } catch (HttpsConnection.HttpsConnectionException e) { diff --git a/app/src/main/res/layout/activity_peertube_upload.xml b/app/src/main/res/layout/activity_peertube_upload.xml new file mode 100644 index 000000000..14ba39705 --- /dev/null +++ b/app/src/main/res/layout/activity_peertube_upload.xml @@ -0,0 +1,100 @@ + + + + + + + +