Skip to content

Commit

Permalink
allow changing the destination of compressed file
Browse files Browse the repository at this point in the history
  • Loading branch information
tibbi committed Sep 3, 2017
1 parent 535b9ce commit 4ad0175
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
Expand Up @@ -3,9 +3,11 @@ package com.simplemobiletools.filemanager.dialogs
import android.support.v7.app.AlertDialog
import android.view.View
import android.view.WindowManager
import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.filemanager.R
import com.simplemobiletools.filemanager.activities.SimpleActivity
import com.simplemobiletools.filemanager.extensions.config
import kotlinx.android.synthetic.main.dialog_compress_as.view.*
import java.io.File

Expand All @@ -17,7 +19,19 @@ class CompressAsDialog(val activity: SimpleActivity, val path: String, val callb
val filename = path.getFilenameFromPath()
val indexOfDot = if (filename.contains('.') && file.isFile) filename.lastIndexOf(".") else filename.length
val baseFilename = filename.substring(0, indexOfDot)
view.file_name.setText(baseFilename)
var realPath = file.parent.trimEnd('/')

view.apply {
file_name.setText(baseFilename)

file_path.text = activity.humanizePath(realPath)
file_path.setOnClickListener {
FilePickerDialog(activity, realPath, false, activity.config.shouldShowHidden, true) {
file_path.text = activity.humanizePath(it)
realPath = it
}
}
}

AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, null)
Expand All @@ -30,7 +44,7 @@ class CompressAsDialog(val activity: SimpleActivity, val path: String, val callb
when {
name.isEmpty() -> activity.toast(R.string.empty_name)
name.isAValidFilename() -> {
val newFile = File(file.parent, "$name.zip")
val newFile = File(realPath, "$name.zip")
if (newFile.exists()) {
activity.toast(R.string.name_taken)
return@OnClickListener
Expand Down
34 changes: 33 additions & 1 deletion app/src/main/res/layout/dialog_compress_as.xml
@@ -1,17 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/dialog_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin">
android:paddingTop="@dimen/medium_margin">

<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/file_path_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_margin"
android:text="@string/path"
android:textSize="@dimen/smaller_text_size"/>

<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/file_path"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/file_path_label"
android:paddingBottom="@dimen/activity_margin"
android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/small_margin"
android:paddingTop="@dimen/small_margin"
tools:text="/storage/emulated/0"/>

<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/file_name_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/file_path"
android:layout_marginTop="@dimen/normal_margin"
android:text="@string/filename"
android:textSize="@dimen/smaller_text_size"/>

<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/file_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/file_name_label"
android:layout_marginLeft="@dimen/normal_margin"
android:layout_marginRight="@dimen/medium_margin"
android:layout_toLeftOf="@+id/file_extension"
android:inputType="textCapSentences"
Expand All @@ -25,6 +56,7 @@
android:layout_alignBottom="@+id/file_name"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/file_name"
android:layout_below="@+id/file_name_label"
android:gravity="center_vertical"
android:text=".zip"
android:textSize="@dimen/normal_text_size"/>
Expand Down

0 comments on commit 4ad0175

Please sign in to comment.