Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 30 additions & 16 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,48 +1,62 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 30
buildToolsVersion "30.0.1"
compileSdkVersion 33

defaultConfig {
applicationId "com.alterpat.voicerecorder"
minSdkVersion 24
targetSdkVersion 30
minSdkVersion 26
targetSdkVersion 33
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '17'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

viewBinding {
enabled = true
}

namespace 'com.alterpat.voicerecorder'
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.8.21"
implementation 'androidx.core:core-ktx:1.10.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'


implementation 'com.google.android.material:material:1.4.0-alpha02'
implementation 'com.google.android.material:material:1.9.0'

def room_version = "2.2.6"

implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-runtime:2.5.1"
kapt "androidx.room:room-compiler:$room_version"

// optional - Kotlin Extensions and Coroutines support for Room
implementation "androidx.room:room-ktx:$room_version"
//ROOM
implementation "androidx.room:room-runtime:2.5.1"
kapt "androidx.room:room-compiler:2.5.1"
implementation "androidx.room:room-ktx:2.5.1"
implementation "androidx.room:room-paging:2.5.1"
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.alterpat.voicerecorder

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.*
import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.alterpat.voicerecorder">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.RECORD_AUDIO" />

Expand All @@ -11,11 +10,12 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".PlayerActivity"></activity>
<activity android:name=".PlayerActivity" />
<activity android:name=".ListingActivity" />
<activity
android:name=".MainActivity"
android:windowSoftInputMode="adjustResize">
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
43 changes: 24 additions & 19 deletions app/src/main/java/com/alterpat/voicerecorder/Adapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,52 @@ import android.view.ViewGroup
import android.widget.CheckBox
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.alterpat.voicerecorder.databinding.ItemviewLayoutBinding
import com.alterpat.voicerecorder.db.AudioRecord
import java.text.SimpleDateFormat
import java.util.*
import java.util.Date

class Adapter(private var audioRecords: List<AudioRecord>,
private val listener: OnItemClickListener) : RecyclerView.Adapter<Adapter.ViewHolder>() {
class Adapter(
private var audioRecords: List<AudioRecord>,
private val listener: OnItemClickListener
) : RecyclerView.Adapter<Adapter.ViewHolder>() {

private var editMode = false
lateinit var binding : ItemviewLayoutBinding

interface OnItemClickListener {
fun onItemClick(position: Int)
fun onItemLongClick(position: Int)
}

inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), View.OnClickListener, View.OnLongClickListener {
var filename : TextView = itemView.findViewById(R.id.filename)
var fileMeta : TextView = itemView.findViewById(R.id.file_meta)
var checkBox : CheckBox = itemView.findViewById(R.id.checkbox)
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView),
View.OnClickListener, View.OnLongClickListener {
var filename: TextView = itemView.findViewById(R.id.filename)
var fileMeta: TextView = itemView.findViewById(R.id.file_meta)
var checkBox: CheckBox = itemView.findViewById(R.id.checkbox)

init {
itemView.setOnClickListener(this)
itemView.setOnLongClickListener(this)
}

override fun onClick(p0: View?) {
val position = adapterPosition // property of the recyclerview class
if(position != RecyclerView.NO_POSITION)
if (position != RecyclerView.NO_POSITION)
listener.onItemClick(position)
}

override fun onLongClick(p0: View?): Boolean {
val position = adapterPosition // property of the recyclerview class
if(position != RecyclerView.NO_POSITION)
if (position != RecyclerView.NO_POSITION)
listener.onItemLongClick(position)
return true
}
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.itemview_layout, parent, false)
binding = ItemviewLayoutBinding.inflate(LayoutInflater.from(parent.context),parent,false)
val view = binding.root
return ViewHolder(view)
}

Expand All @@ -54,44 +61,42 @@ class Adapter(private var audioRecords: List<AudioRecord>,
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
if(position != RecyclerView.NO_POSITION){
if (position != RecyclerView.NO_POSITION) {
var audioRecord = audioRecords[position]
holder.filename.text = audioRecord.filename
val sdf = SimpleDateFormat("dd/MM/yy")
val netDate = Date(audioRecord.date)
val date =sdf.format(netDate)
val date = sdf.format(netDate)

holder.fileMeta.text = "${audioRecord.duration} $date"

Log.d("ListingTag", audioRecord.isChecked.toString())

if(editMode) {
if (editMode) {
holder.checkBox.visibility = View.VISIBLE
if (audioRecord.isChecked)
holder.checkBox.isChecked = audioRecord.isChecked
}else {
} else {
holder.checkBox.visibility = View.GONE
audioRecord.isChecked = false
holder.checkBox.isChecked = false
}
}
}

fun setData(audioRecords: List<AudioRecord>){
fun setData(audioRecords: List<AudioRecord>) {
this.audioRecords = audioRecords
notifyDataSetChanged()
}

fun setEditMode(mode: Boolean){
fun setEditMode(mode: Boolean) {
editMode = mode
notifyDataSetChanged()
}

fun isEditMode():Boolean{
fun isEditMode(): Boolean {
return editMode
}




}
22 changes: 12 additions & 10 deletions app/src/main/java/com/alterpat/voicerecorder/BottomSheet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ import android.view.ViewGroup
import android.view.WindowManager
import android.view.inputmethod.InputMethodManager
import android.widget.Button
import com.alterpat.voicerecorder.databinding.ActivityMainBinding
import com.alterpat.voicerecorder.databinding.BottomSheetBinding
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.google.android.material.textfield.TextInputEditText
import java.io.File


class BottomSheet: BottomSheetDialogFragment {
class BottomSheet : BottomSheetDialogFragment {

// Step 1 - This interface defines the type of messages I want to communicate to my owner
interface OnClickListener {
// These methods are the different events and
// need to pass relevant arguments related to the event triggered
fun onCancelClicked()
fun onOkClicked(filePath: String, filename: String)
}

// Step 2 - This variable represents the listener passed in by the owning object
// The listener must implement the events interface and passes messages up to the parent.
private lateinit var listener: OnClickListener
private lateinit var binding: BottomSheetBinding

private lateinit var filename: String
private lateinit var dirPath: String

constructor(dirPath: String, filename : String, listener: OnClickListener){
constructor(dirPath: String, filename: String, listener: OnClickListener) {
this.dirPath = dirPath
this.filename = filename
this.listener = listener
Expand All @@ -41,7 +41,8 @@ class BottomSheet: BottomSheetDialogFragment {
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
var view = inflater.inflate(R.layout.bottom_sheet, container)
binding = BottomSheetBinding.inflate(layoutInflater)
var view = binding.root
var editText = view.findViewById<TextInputEditText>(R.id.filenameInput)


Expand All @@ -61,9 +62,9 @@ class BottomSheet: BottomSheetDialogFragment {

// update filename if need
val updatedFilename = editText.text.toString()
if(updatedFilename != filename){
if (updatedFilename != filename) {
var newFile = File("$dirPath$updatedFilename.mp3")
File(dirPath+filename).renameTo(newFile)
File(dirPath + filename).renameTo(newFile)
}

// add entry to db
Expand All @@ -80,7 +81,7 @@ class BottomSheet: BottomSheetDialogFragment {
// hide keyboard
hideKeyboard(view)
// delete file from storage
File(dirPath+filename).delete()
File(dirPath + filename).delete()

// dismiss dialog
dismiss()
Expand All @@ -95,7 +96,8 @@ class BottomSheet: BottomSheetDialogFragment {

private fun showKeyboard(view: View) {
if (view.requestFocus()) {
val imm = view.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager?
val imm =
view.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager?
imm?.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0)
}
}
Expand Down
Loading