| @@ -27,6 +27,7 @@ dependencies { | |||||
| implementation fileTree(dir: 'libs', include: ['*.jar']) | implementation fileTree(dir: 'libs', include: ['*.jar']) | ||||
| implementation 'com.android.support:appcompat-v7:26.0.2' | implementation 'com.android.support:appcompat-v7:26.0.2' | ||||
| implementation 'com.android.support.constraint:constraint-layout:1.0.2' | implementation 'com.android.support.constraint:constraint-layout:1.0.2' | ||||
| implementation 'com.android.support:design:26.1.0' | |||||
| testImplementation 'junit:junit:4.12' | testImplementation 'junit:junit:4.12' | ||||
| androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', { | androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', { | ||||
| exclude group: 'com.android.support', module: 'support-annotations' | exclude group: 'com.android.support', module: 'support-annotations' | ||||
| @@ -8,6 +8,13 @@ import android.os.Bundle | |||||
| import android.widget.Button | import android.widget.Button | ||||
| import android.widget.EditText | import android.widget.EditText | ||||
| import android.provider.OpenableColumns | import android.provider.OpenableColumns | ||||
| import android.support.v4.content.ContextCompat | |||||
| import android.support.v4.content.res.ResourcesCompat | |||||
| import android.support.v7.widget.Toolbar | |||||
| import android.util.Log | |||||
| import android.view.Menu | |||||
| import android.view.MenuItem | |||||
| import android.view.View | |||||
| import android.widget.TextView | import android.widget.TextView | ||||
| import kotlinx.android.synthetic.main.activity_edit.* | import kotlinx.android.synthetic.main.activity_edit.* | ||||
| @@ -27,23 +34,16 @@ class EditActivity : AppCompatActivity() { | |||||
| super.onCreate(savedInstanceState) | super.onCreate(savedInstanceState) | ||||
| setContentView(R.layout.activity_edit) | setContentView(R.layout.activity_edit) | ||||
| val editToolbar = findViewById<View>(R.id.edit_toolbar) as Toolbar | |||||
| setSupportActionBar(editToolbar) | |||||
| editToolbar.navigationIcon = ResourcesCompat.getDrawable(resources, R.drawable.ic_arrow_back_black_24dp, null) | |||||
| editToolbar.setNavigationOnClickListener(View.OnClickListener { onBackPressed() }) | |||||
| val captionEditText = findViewById<EditText>(R.id.captionEditText) | val captionEditText = findViewById<EditText>(R.id.captionEditText) | ||||
| captionEditText.setText(intent.getStringExtra("caption")) | captionEditText.setText(intent.getStringExtra("caption")) | ||||
| fileTextView.text = intent.getStringExtra("fileName") | |||||
| val okButton = findViewById<Button>(R.id.okButton) | |||||
| okButton.setOnClickListener { | |||||
| val data = Intent() | |||||
| data.putExtra("index", intent.getIntExtra("index", -1)) | |||||
| data.putExtra("caption", captionEditText.text.toString()) | |||||
| data.putExtra("fileName", fileTextView.text.toString()) | |||||
| if (currentUri != null) { | |||||
| data.putExtra("uri", currentUri) | |||||
| } | |||||
| setResult(Activity.RESULT_OK, data) | |||||
| finish() | |||||
| } | |||||
| val fileName = intent.getStringExtra("fileName") | |||||
| if (fileName.isEmpty()) fileTextView.text = "No file selected" else fileTextView.text = fileName | |||||
| val selectButton = findViewById<Button>(R.id.selectButton) | val selectButton = findViewById<Button>(R.id.selectButton) | ||||
| selectButton.setOnClickListener { | selectButton.setOnClickListener { | ||||
| @@ -53,15 +53,38 @@ class EditActivity : AppCompatActivity() { | |||||
| startActivityForResult(intent, 123) | startActivityForResult(intent, 123) | ||||
| } | } | ||||
| } | |||||
| val deleteButton = findViewById<Button>(R.id.deleteButton) | |||||
| deleteButton.setOnClickListener { | |||||
| val data = Intent() | |||||
| data.putExtra("index", intent.getIntExtra("index", -1)) | |||||
| data.putExtra("delete", true) | |||||
| setResult(Activity.RESULT_OK, data) | |||||
| finish() | |||||
| override fun onCreateOptionsMenu(menu: Menu?): Boolean { | |||||
| val inflater = menuInflater | |||||
| inflater.inflate(R.menu.edit, menu) | |||||
| return true | |||||
| } | |||||
| override fun onOptionsItemSelected(item: MenuItem?): Boolean { | |||||
| if (item != null) { | |||||
| when (item.itemId) { | |||||
| R.id.submit -> { | |||||
| val data = Intent() | |||||
| data.putExtra("index", intent.getIntExtra("index", -1)) | |||||
| data.putExtra("caption", captionEditText.text.toString()) | |||||
| data.putExtra("fileName", fileTextView.text.toString()) | |||||
| if (currentUri != null) { | |||||
| data.putExtra("uri", currentUri) | |||||
| } | |||||
| setResult(Activity.RESULT_OK, data) | |||||
| finish() | |||||
| } | |||||
| R.id.delete -> { | |||||
| val data = Intent() | |||||
| data.putExtra("index", intent.getIntExtra("index", -1)) | |||||
| data.putExtra("delete", true) | |||||
| setResult(Activity.RESULT_OK, data) | |||||
| finish() | |||||
| } | |||||
| } | |||||
| } | } | ||||
| return super.onOptionsItemSelected(item) | |||||
| } | } | ||||
| private var currentUri: Uri? = null | private var currentUri: Uri? = null | ||||
| @@ -238,6 +238,7 @@ class MainActivity : AppCompatActivity() { | |||||
| parent.removeView(button) | parent.removeView(button) | ||||
| saveNumButtons() | saveNumButtons() | ||||
| organizeButtons() | organizeButtons() | ||||
| // TODO: Do we need to remove some preferences? | |||||
| } else { | } else { | ||||
| val caption = data.getStringExtra("caption") | val caption = data.getStringExtra("caption") | ||||
| if (caption != null) { | if (caption != null) { | ||||
| @@ -0,0 +1,9 @@ | |||||
| <vector xmlns:android="http://schemas.android.com/apk/res/android" | |||||
| android:width="24dp" | |||||
| android:height="24dp" | |||||
| android:viewportWidth="24.0" | |||||
| android:viewportHeight="24.0"> | |||||
| <path | |||||
| android:fillColor="#FF000000" | |||||
| android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z"/> | |||||
| </vector> | |||||
| @@ -0,0 +1,9 @@ | |||||
| <vector xmlns:android="http://schemas.android.com/apk/res/android" | |||||
| android:width="24dp" | |||||
| android:height="24dp" | |||||
| android:viewportWidth="24.0" | |||||
| android:viewportHeight="24.0"> | |||||
| <path | |||||
| android:fillColor="#FF000000" | |||||
| android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z"/> | |||||
| </vector> | |||||
| @@ -0,0 +1,9 @@ | |||||
| <vector xmlns:android="http://schemas.android.com/apk/res/android" | |||||
| android:width="24dp" | |||||
| android:height="24dp" | |||||
| android:viewportWidth="24.0" | |||||
| android:viewportHeight="24.0"> | |||||
| <path | |||||
| android:fillColor="#FF000000" | |||||
| android:pathData="M9,16.2L4.8,12l-1.4,1.4L9,19 21,7l-1.4,-1.4L9,16.2z"/> | |||||
| </vector> | |||||
| @@ -4,24 +4,41 @@ | |||||
| xmlns:tools="http://schemas.android.com/tools" | xmlns:tools="http://schemas.android.com/tools" | ||||
| android:layout_width="match_parent" | android:layout_width="match_parent" | ||||
| android:layout_height="match_parent" | android:layout_height="match_parent" | ||||
| android:paddingLeft="16dp" | |||||
| android:paddingRight="16dp" | |||||
| android:paddingTop="16dp" | |||||
| tools:context="de.mlte.soundboard.EditActivity"> | tools:context="de.mlte.soundboard.EditActivity"> | ||||
| <EditText | |||||
| android:id="@+id/captionEditText" | |||||
| <android.support.v7.widget.Toolbar | |||||
| android:id="@+id/edit_toolbar" | |||||
| android:layout_width="match_parent" | |||||
| android:layout_height="?attr/actionBarSize" | |||||
| android:background="?attr/colorPrimary" | |||||
| android:elevation="4dp" | |||||
| android:theme="@style/ThemeOverlay.AppCompat.ActionBar" | |||||
| app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> | |||||
| <android.support.design.widget.TextInputLayout | |||||
| android:id="@+id/input_layout" | |||||
| android:layout_width="match_parent" | android:layout_width="match_parent" | ||||
| android:layout_height="wrap_content" | android:layout_height="wrap_content" | ||||
| android:inputType="textPersonName" | |||||
| android:hint="Name" /> | |||||
| android:layout_below="@+id/edit_toolbar" | |||||
| android:layout_marginLeft="16dp" | |||||
| android:layout_marginRight="16dp" | |||||
| android:layout_marginTop="16dp"> | |||||
| <android.support.design.widget.TextInputEditText | |||||
| android:id="@+id/captionEditText" | |||||
| android:layout_width="match_parent" | |||||
| android:layout_height="wrap_content" | |||||
| android:hint="Name" | |||||
| android:inputType="textPersonName" /> | |||||
| </android.support.design.widget.TextInputLayout> | |||||
| <Button | <Button | ||||
| android:id="@+id/selectButton" | android:id="@+id/selectButton" | ||||
| android:layout_width="wrap_content" | android:layout_width="wrap_content" | ||||
| android:layout_height="wrap_content" | android:layout_height="wrap_content" | ||||
| android:layout_alignParentRight="true" | android:layout_alignParentRight="true" | ||||
| android:layout_below="@+id/captionEditText" | |||||
| android:layout_below="@+id/input_layout" | |||||
| android:layout_marginRight="16dp" | |||||
| android:text="Select File ..." /> | android:text="Select File ..." /> | ||||
| <TextView | <TextView | ||||
| @@ -30,29 +47,9 @@ | |||||
| android:layout_height="wrap_content" | android:layout_height="wrap_content" | ||||
| android:layout_alignBaseline="@+id/selectButton" | android:layout_alignBaseline="@+id/selectButton" | ||||
| android:layout_alignParentLeft="true" | android:layout_alignParentLeft="true" | ||||
| android:layout_below="@+id/captionEditText" | |||||
| android:layout_toLeftOf="@id/selectButton" /> | |||||
| <Button | |||||
| android:id="@+id/okButton" | |||||
| android:layout_width="wrap_content" | |||||
| android:layout_height="wrap_content" | |||||
| android:layout_alignParentEnd="true" | |||||
| android:layout_alignParentLeft="true" | |||||
| android:layout_below="@+id/selectButton" | |||||
| android:layout_marginTop="48dp" | |||||
| android:text="OK" /> | |||||
| <Button | |||||
| android:id="@+id/deleteButton" | |||||
| android:layout_width="wrap_content" | |||||
| android:layout_height="wrap_content" | |||||
| android:layout_alignBaseline="@+id/okButton" | |||||
| android:layout_alignParentStart="false" | |||||
| android:layout_marginRight="8dp" | |||||
| android:layout_toLeftOf="@+id/okButton" | |||||
| android:backgroundTint="@android:color/holo_red_dark" | |||||
| android:text="Delete" | |||||
| android:textColor="@android:color/white" /> | |||||
| android:layout_below="@+id/input_layout" | |||||
| android:layout_marginLeft="16dp" | |||||
| android:layout_toLeftOf="@id/selectButton" | |||||
| android:text="@string/no_file_selected"/> | |||||
| </RelativeLayout> | </RelativeLayout> | ||||
| @@ -0,0 +1,16 @@ | |||||
| <?xml version="1.0" encoding="utf-8"?> | |||||
| <menu xmlns:android="http://schemas.android.com/apk/res/android" | |||||
| xmlns:app="http://schemas.android.com/apk/res-auto"> | |||||
| <item | |||||
| android:id="@+id/submit" | |||||
| android:icon="@drawable/ic_done_black_24dp" | |||||
| android:title="@string/action_done" | |||||
| app:showAsAction="ifRoom|withText"/> | |||||
| <item | |||||
| android:id="@+id/delete" | |||||
| android:icon="@drawable/ic_delete_black_24dp" | |||||
| android:title="@string/action_delete" | |||||
| app:showAsAction="never|withText" /> | |||||
| </menu> | |||||
| @@ -1,4 +1,7 @@ | |||||
| <resources> | <resources> | ||||
| <string name="app_name">Soundboard</string> | <string name="app_name">Soundboard</string> | ||||
| <string name="action_add_new">Add new</string> | <string name="action_add_new">Add new</string> | ||||
| <string name="action_done">Done</string> | |||||
| <string name="action_delete">Delete</string> | |||||
| <string name="no_file_selected">No file selected</string> | |||||
| </resources> | </resources> | ||||