Skip to content

Commit

Permalink
Reimplement picking destination folders when adding transfers via Intent
Browse files Browse the repository at this point in the history
  • Loading branch information
DSteve595 committed Dec 28, 2016
1 parent 5a48f64 commit d6abcad
Show file tree
Hide file tree
Showing 48 changed files with 479 additions and 445 deletions.
7 changes: 5 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ buildscript {

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'io.fabric'

repositories {
Expand All @@ -23,8 +24,8 @@ android {
applicationId 'com.stevenschoen.putionew'
minSdkVersion 19
targetSdkVersion 25
versionCode 108
versionName '4.0.6'
versionCode 109
versionName '4.0.7'
multiDexEnabled true
}
buildTypes {
Expand Down Expand Up @@ -82,6 +83,8 @@ dependencies {
compile 'com.tbruyelle.rxpermissions:rxpermissions:0.9.1@aar'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.aurelhubert:ahbottomnavigation:2.0.2'
compile 'nz.bradcampbell:paperparcel:2.0.0-beta1'
kapt 'nz.bradcampbell:paperparcel-compiler:2.0.0-beta1'
}
repositories {
mavenCentral()
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
android:name=".files.FileFinishedActivity"
android:theme="@style/Putio.Dialog"/>
<activity
android:name=".transfers.AddTransferActivity"
android:name=".transfers.add.AddTransferActivity"
android:excludeFromRecents="true"
android:label="@string/add_transfer"
android:taskAffinity="com.stevenschoen.putionew.addtransfertask"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import com.stevenschoen.putionew.fragments.Account;
import com.stevenschoen.putionew.model.files.PutioFile;
import com.stevenschoen.putionew.model.transfers.PutioTransfer;
import com.stevenschoen.putionew.transfers.AddTransferActivity;
import com.stevenschoen.putionew.transfers.Transfers;
import com.stevenschoen.putionew.transfers.add.AddTransferActivity;
import com.stevenschoen.putionew.tv.TvActivity;

import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -189,7 +189,7 @@ public void onClick(View v) {
}
Intent addTransferIntent = new Intent(PutioActivity.this, AddTransferActivity.class);
if (destinationFolder != null) {
addTransferIntent.putExtra(AddTransferActivity.EXTRA_DESTINATION_FOLDER, destinationFolder);
addTransferIntent.putExtra(AddTransferActivity.EXTRA_PRECHOSEN_DESTINATION_FOLDER, destinationFolder);
}
startActivity(addTransferIntent);
}
Expand Down
46 changes: 11 additions & 35 deletions app/src/main/java/com/stevenschoen/putionew/PutioUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,11 @@

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;

import javax.net.ssl.HttpsURLConnection;

import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
Expand Down Expand Up @@ -179,10 +173,10 @@ public void downloadFiles(final Activity activity, final int actionWhenDone, fin
List<Observable<Long>> downloadIds = new ArrayList<>(files.length);
for (PutioFile file : files) {
if (file.isFolder()) {
long[] folder = new long[]{file.id};
downloadIds.add(downloadZipWithoutUrl(activity, folder, file.name));
long[] folder = new long[]{file.getId()};
downloadIds.add(downloadZipWithoutUrl(activity, folder, file.getName()));
} else {
downloadIds.add(downloadFileWithoutUrl(activity, file.id, file.name));
downloadIds.add(downloadFileWithoutUrl(activity, file.getId(), file.getName()));
}
}

Expand Down Expand Up @@ -304,7 +298,7 @@ public void stream(Context context, PutioFile file, String url, List<PutioSubtit

for (int i = 0; i < subtitles.size(); i++) {
PutioSubtitle subtitle = subtitles.get(i);
subtitleUris[i] = Uri.parse(subtitle.getUrl(PutioSubtitle.FORMAT_SRT, file.id, tokenWithStuff));
subtitleUris[i] = Uri.parse(subtitle.getUrl(PutioSubtitle.FORMAT_SRT, file.getId(), tokenWithStuff));
subtitleNames[i] = subtitle.getLanguage();
}

Expand Down Expand Up @@ -350,7 +344,7 @@ protected GetStreamUrlAndPlayResult doInBackground(String... params) {
}
result.url = finalUrl;

result.subtitles = getRestInterface().subtitles(file.id).toBlocking().first().getSubtitles();
result.subtitles = getRestInterface().subtitles(file.getId()).toBlocking().first().getSubtitles();

return result;
}
Expand All @@ -365,9 +359,9 @@ public void onPostExecute(GetStreamUrlAndPlayResult result) {
e.printStackTrace();
}
int type;
if (file.contentType.contains("audio")) {
if (file.getContentType().contains("audio")) {
type = PutioUtils.TYPE_AUDIO;
} else if (file.contentType.contains("video")) {
} else if (file.getContentType().contains("video")) {
type = PutioUtils.TYPE_VIDEO;
} else {
type = PutioUtils.TYPE_VIDEO;
Expand All @@ -385,26 +379,8 @@ private static class GetStreamUrlAndPlayResult {
List<PutioSubtitle> subtitles;
}

public InputStream getDefaultSubtitleData(long id) throws SocketTimeoutException {
URL url = null;
try {
url = new URL(baseUrl + "/files/" + id + "/subtitles/default" + tokenWithStuff + "&format=webvtt");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setConnectTimeout(8000);

return connection.getInputStream();
} catch (MalformedURLException e1) {
e1.printStackTrace();
} catch (SocketTimeoutException e) {
throw new SocketTimeoutException();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

public void copyDownloadLink(final Context context, PutioFile file) {
String url = baseUrl + "/files/" + file.id + "/download" + tokenWithStuff;
String url = baseUrl + "files/" + file.getId() + "/download" + tokenWithStuff;
copy(context, "Download link", url);
Toast.makeText(context, context.getString(R.string.readytopaste),
Toast.LENGTH_SHORT).show();
Expand All @@ -413,7 +389,7 @@ public void copyDownloadLink(final Context context, PutioFile file) {
public void copyZipDownloadLink(Context context, PutioFile... files) {
long[] fileIds = new long[files.length];
for (int i = 0; i < files.length; i++) {
fileIds[i] = files[i].id;
fileIds[i] = files[i].getId();
}
String url = getZipDownloadUrl(fileIds);
copy(context, "Download link", url);
Expand Down Expand Up @@ -443,12 +419,12 @@ public static String resolveRedirect(String url) throws IOException {
}

public String getFileDownloadUrl(long id) {
return baseUrl + "/files/" + id + "/download" + tokenWithStuff;
return baseUrl + "files/" + id + "/download" + tokenWithStuff;
}

public String getZipDownloadUrl(long... ids) {
String idsString = longsToString(ids);
return baseUrl + "/files/zip?file_ids=" + idsString + tokenWithStuff.replace("?", "&"); // TODO hacky
return baseUrl + "files/zip?file_ids=" + idsString + tokenWithStuff.replace("?", "&"); // TODO hacky
}

public static boolean idIsDownloaded(long id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ abstract class BaseCastActivity : AppCompatActivity(), PutioApplication.CastCall
setMediaTracks(subtitles.orEmpty().mapIndexed { i, sub ->
MediaTrack.Builder(i.toLong(), MediaTrack.TYPE_TEXT)
.setContentId(sub.getUrl(PutioSubtitle.FORMAT_WEBVTT, file.id, utils.tokenWithStuff))
.setContentType("text/vtt")
.setSubtype(MediaTrack.SUBTYPE_SUBTITLES)
.setName(sub.name)
.setLanguage(sub.language)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import com.stevenschoen.putionew.R

class DestinationFolderActivity : AppCompatActivity() {

companion object {
val RESULT_EXTRA_FOLDER = "folder"
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Expand All @@ -28,7 +24,7 @@ class DestinationFolderActivity : AppCompatActivity() {

val toolbarView = findViewById(R.id.destination_toolbar) as Toolbar
setSupportActionBar(toolbarView)
toolbarView.setNavigationIcon(R.drawable.ic_toolbarnav_close)
toolbarView.setNavigationIcon(R.drawable.ic_toolbar_nav_close_black)
toolbarView.setNavigationOnClickListener { finish() }

findViewById(R.id.destination_cancel).setOnClickListener {
Expand All @@ -51,4 +47,8 @@ class DestinationFolderActivity : AppCompatActivity() {
super.onBackPressed()
}
}

companion object {
val RESULT_EXTRA_FOLDER = "folder"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class FileDetailsFragment : RxFragment() {

val infoSize = holderInfo.findViewById(R.id.holder_fileinfo_size)
val textSize = infoSize.findViewById(R.id.text_fileinfo_size) as TextView
textSize.text = PutioUtils.humanReadableByteCount(file.size, false)
textSize.text = PutioUtils.humanReadableByteCount(file.size!!, false)

val infoCrc32 = holderInfo.findViewById(R.id.holder_fileinfo_crc32)
val textCrc32 = infoCrc32.findViewById(R.id.text_fileinfo_crc32) as TextView
Expand All @@ -181,7 +181,7 @@ class FileDetailsFragment : RxFragment() {
if (mp4Status == PutioMp4Status.Status.Completed) {
mp4 = checkBoxMp4Available.isChecked
}
} else if (file.isMp4Available) {
} else if (file.isMp4Available!!) {
mp4 = checkBoxMp4Available.isChecked
}
}
Expand Down Expand Up @@ -331,7 +331,7 @@ class FileDetailsFragment : RxFragment() {
infoMp4Already.visibility = View.GONE
infoMp4Available.visibility = View.GONE
infoMp4Converting.visibility = View.VISIBLE
infoMp4ConvertingText.text = getString(R.string.converting_mp4) + " (${status.percentDone}%)"
infoMp4ConvertingText.text = "${getString(R.string.converting_mp4)} (${status.percentDone}%)"
infoMp4NotAvailable.visibility = View.GONE
}
PutioMp4Status.Status.Completed -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.stevenschoen.putionew.files

import android.support.v7.widget.RecyclerView
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -60,18 +61,20 @@ class FileListAdapter(private val data: List<PutioFile>,
}

override fun onBindViewHolder(holder: FileHolder, position: Int) {
if (holder.root is Checkable) {
(holder.root as Checkable).isChecked = isPositionChecked(position)
if (holder.itemView is Checkable) {
holder.itemView.isChecked = isPositionChecked(position)
}

val file = data[position]

holder.textName.text = file.name
holder.textDescription.text = PutioUtils.humanReadableByteCount(file.size, false)
if (file.icon != null && !file.icon.isEmpty()) {
if (file.icon.endsWith("folder.png")) {
Picasso.with(holder.iconImg.context).load(R.drawable.ic_putio_folder).into(holder.iconImg)
} else {
holder.textDescription.text = PutioUtils.humanReadableByteCount(file.size!!, false)
Log.d("addtransfer_pick_destination", "${file.name} isFolder: ${file.isFolder}")
if (file.isFolder) {
Picasso.with(holder.iconImg.context).cancelRequest(holder.iconImg)
holder.iconImg.setImageResource(R.drawable.ic_putio_folder_accent)
} else {
if (!file.icon.isNullOrEmpty()) {
Picasso.with(holder.iconImg.context).load(file.icon).into(holder.iconImg)
}
}
Expand Down Expand Up @@ -171,17 +174,17 @@ class FileListAdapter(private val data: List<PutioFile>,
fun onItemsCheckedChanged()
}

inner class FileHolder(var root: View) : RecyclerView.ViewHolder(root) {
val textName = root.findViewById(R.id.text_file_name) as TextView
val textDescription = root.findViewById(R.id.text_file_description) as TextView
val iconImg = root.findViewById(R.id.icon_file_img) as ImageView
val iconAccessed = root.findViewById(R.id.icon_file_accessed) as ImageView
inner class FileHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val textName = itemView.findViewById(R.id.text_file_name) as TextView
val textDescription = itemView.findViewById(R.id.text_file_description) as TextView
val iconImg = itemView.findViewById(R.id.icon_file_img) as ImageView
val iconAccessed = itemView.findViewById(R.id.icon_file_accessed) as ImageView

init {
root.setOnClickListener {
itemView.setOnClickListener {
onFileClicked.invoke(data[adapterPosition], this)
}
root.setOnLongClickListener {
itemView.setOnLongClickListener {
onFileLongClicked.invoke(data[adapterPosition], this)
true
}
Expand Down
60 changes: 30 additions & 30 deletions app/src/main/java/com/stevenschoen/putionew/files/FolderFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,6 @@ import rx.android.schedulers.AndroidSchedulers

class FolderFragment : FileListFragment<FileListFragment.Callbacks>() {

companion object {
const val EXTRA_FOLDER = "folder"
const val EXTRA_PAD_FOR_FAB = "padforfab"
const val EXTRA_SHOW_SEARCH = "show_search"
const val EXTRA_SHOW_CREATEFOLDER = "show_createfolder"

const val REQUEST_CHOOSE_MOVE_DESTINATION = 1

const val FRAGTAG_SELECTION = "selection"
const val FRAGTAG_RENAME = "rename"
const val FRAGTAG_DOWNLOAD_INDIVIDUALORZIP = "dl_indivorzip"
const val FRAGTAG_DELETE = "delete"
const val FRAGTAG_CREATE_FOLDER = "create_folder"

fun newInstance(context: Context, folder: PutioFile,
canSelect: Boolean,
padForFab: Boolean, showSearch: Boolean, showCreateFolder: Boolean): FolderFragment {
if (!folder.isFolder) {
throw IllegalStateException("FolderFragment created on a file, not a folder: ${folder.name} (ID ${folder.id})")
}
val args = Bundle()
args.putParcelable(EXTRA_FOLDER, folder)
args.putBoolean(EXTRA_PAD_FOR_FAB, padForFab)
args.putBoolean(EXTRA_SHOW_SEARCH, showSearch)
args.putBoolean(EXTRA_SHOW_CREATEFOLDER, showCreateFolder)
return addArguments(Fragment.instantiate(context, FolderFragment::class.java.name, args) as FolderFragment,
canSelect)
}
}

val folder by lazy { arguments.getParcelable<PutioFile>(EXTRA_FOLDER) }
val padForFab by lazy { arguments.getBoolean(EXTRA_PAD_FOR_FAB) }
val showSearch by lazy { arguments.getBoolean(EXTRA_SHOW_SEARCH) }
Expand Down Expand Up @@ -196,4 +166,34 @@ class FolderFragment : FileListFragment<FileListFragment.Callbacks>() {
override fun isRefreshing(): Boolean {
return folderLoader!!.isRefreshing()
}

companion object {
const val EXTRA_FOLDER = "folder"
const val EXTRA_PAD_FOR_FAB = "padforfab"
const val EXTRA_SHOW_SEARCH = "show_search"
const val EXTRA_SHOW_CREATEFOLDER = "show_createfolder"

const val REQUEST_CHOOSE_MOVE_DESTINATION = 1

const val FRAGTAG_SELECTION = "selection"
const val FRAGTAG_RENAME = "rename"
const val FRAGTAG_DOWNLOAD_INDIVIDUALORZIP = "dl_indivorzip"
const val FRAGTAG_DELETE = "delete"
const val FRAGTAG_CREATE_FOLDER = "create_folder"

fun newInstance(context: Context, folder: PutioFile,
canSelect: Boolean,
padForFab: Boolean, showSearch: Boolean, showCreateFolder: Boolean): FolderFragment {
if (!folder.isFolder) {
throw IllegalStateException("FolderFragment created on a file, not a folder: ${folder.name} (ID ${folder.id})")
}
val args = Bundle()
args.putParcelable(EXTRA_FOLDER, folder)
args.putBoolean(EXTRA_PAD_FOR_FAB, padForFab)
args.putBoolean(EXTRA_SHOW_SEARCH, showSearch)
args.putBoolean(EXTRA_SHOW_CREATEFOLDER, showCreateFolder)
return addArguments(Fragment.instantiate(context, FolderFragment::class.java.name, args) as FolderFragment,
canSelect)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SearchLoader(context: Context, private val parentFolder: PutioFile, val qu
searchSubject.onNext(response.files)
}, { error ->
searchSubscription = null
Log.d("asdf", "error: $error")
Log.d("addtransfer_pick_destination", "error: $error")
})
}

Expand Down
Loading

0 comments on commit d6abcad

Please sign in to comment.