Skip to content

Commit

Permalink
chore: release 1.4.0 (#453)
Browse files Browse the repository at this point in the history
chore: release 1.4.0
  • Loading branch information
iamareebjamal authored Jul 23, 2019
2 parents 23a12ff + 2622a20 commit 0eeff55
Show file tree
Hide file tree
Showing 20 changed files with 334 additions and 58 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ cache:
- "${TRAVIS_BUILD_DIR}/gradle/wrapper/dists/"
- "$HOME/.gradle/caches/"
- "$HOME/.gradle/wrapper/"
install:
- echo yes | sdkmanager "platforms;android-28"
before_script:
- bash scripts/prep-key.sh
script:
Expand Down
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ android {
applicationId 'org.fossasia.badgemagic'
minSdkVersion versions.minSdk
targetSdkVersion versions.targetSdk
versionCode 5
versionName '1.3.0'
versionCode 6
versionName '1.4.0'
vectorDrawables.useSupportLibrary = true
}

Expand Down Expand Up @@ -93,7 +93,7 @@ dependencies {
implementation "org.koin:koin-androidx-viewmodel:${versions.koin_version}"

//Material Design
implementation 'com.google.android.material:material:1.1.0-alpha07'
implementation 'com.google.android.material:material:1.1.0-alpha08'

//Timber
implementation 'com.jakewharton.timber:timber:4.7.1'
Expand All @@ -103,7 +103,7 @@ dependencies {
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
testImplementation 'com.nhaarman:mockito-kotlin-kt1.1:1.5.0'
testImplementation 'org.amshove.kluent:kluent:1.51'
testImplementation 'org.amshove.kluent:kluent:1.53'

// Leak Canary
debugImplementation "com.squareup.leakcanary:leakcanary-android:${versions.leak_canary}"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".ui.EditBadgeActivity" android:screenOrientation="landscape">
</activity>
<activity
android:name=".ui.DrawerActivity"
android:label="@string/app_name"
Expand All @@ -48,6 +46,8 @@
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
</activity>
<activity android:name=".ui.EditBadgeActivity" android:screenOrientation="landscape"/>
<activity android:name=".ui.EditClipartActivity" android:screenOrientation="landscape"/>

<provider
android:name="androidx.core.content.FileProvider"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package org.fossasia.badgemagic.adapter

import android.graphics.Bitmap
import android.content.Intent
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
import androidx.databinding.DataBindingUtil
import org.fossasia.badgemagic.R
import org.fossasia.badgemagic.data.SavedClipart
import org.fossasia.badgemagic.databinding.RecyclerItemSavedClipartBinding
import org.fossasia.badgemagic.ui.EditClipartActivity
import org.fossasia.badgemagic.viewmodels.SavedClipartViewModel

class SavedClipartsAdapter(
private var clipartList: List<Bitmap>,
private var clipartList: List<SavedClipart>,
private val viewModel: SavedClipartViewModel
) : RecyclerView.Adapter<SavedClipartsViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SavedClipartsViewHolder {
Expand All @@ -22,14 +24,21 @@ class SavedClipartsAdapter(
override fun getItemCount(): Int = clipartList.size

override fun onBindViewHolder(holder: SavedClipartsViewHolder, position: Int) {
holder.bind(clipartList[position])
holder.getBindingView().setOnClickListener {
holder.bind(clipartList[position].bitmap)
holder.getDeleteButton().setOnClickListener {
viewModel.deleteClipart(position)
Toast.makeText(it.context, "Delete Clipart Successfully", Toast.LENGTH_LONG).show()
}
holder.getEditButton().setOnClickListener {
it.context.startActivity(
Intent(it.context, EditClipartActivity::class.java).apply {
putExtra("fileName", clipartList[position].fileName)
}
)
}
}

fun setList(list: List<Bitmap>) {
fun setList(list: List<SavedClipart>) {
clipartList = list
notifyDataSetChanged()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.fossasia.badgemagic.adapter

import android.graphics.Bitmap
import androidx.appcompat.widget.AppCompatImageView
import androidx.recyclerview.widget.RecyclerView
import org.fossasia.badgemagic.R
import org.fossasia.badgemagic.databinding.RecyclerItemSavedClipartBinding

class SavedClipartsViewHolder(private val binding: RecyclerItemSavedClipartBinding) : RecyclerView.ViewHolder(binding.root) {
Expand All @@ -10,4 +12,6 @@ class SavedClipartsViewHolder(private val binding: RecyclerItemSavedClipartBindi
}

fun getBindingView() = binding.root
fun getDeleteButton(): AppCompatImageView = getBindingView().findViewById(R.id.button_delete)
fun getEditButton(): AppCompatImageView = getBindingView().findViewById(R.id.button_edit)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ fun setBadgeDrawState(badge: DrawBadgeLayout, drawModeState: ObservableField<Dra
drawModeState.get()?.let { badge.changeDrawState(it) }
}

@BindingAdapter("drawingJSON")
fun setBadgeValues(badge: DrawBadgeLayout, drawJSON: ObservableField<String>) {
@BindingAdapter("drawingBadgeJSON")
fun setEditBadgeValues(badge: DrawBadgeLayout, drawJSON: ObservableField<String>) {
val badgeConfig = SendingUtils.getBadgeFromJSON(drawJSON.get() ?: "{}")
badgeConfig?.hexStrings?.let { badge.setValue(it) }
}

@BindingAdapter("drawingClipartJSON")
fun setEditClipartValues(badge: DrawBadgeLayout, drawJSON: ObservableField<List<String>>) {
drawJSON.get()?.let { badge.setValue(it) }
}

@BindingAdapter("changeColor")
fun changeColorState(imageView: ImageView, isEnabled: ObservableBoolean) {
imageView.setColorFilter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.koin.core.inject

class ClipArtService : KoinComponent {
private val clipArts = MutableLiveData<SparseArray<Drawable>>()
private val storageClipArts = MutableLiveData<HashMap<String, Drawable?>>()
private val resourceHelper: Resource by inject()

init {
Expand Down Expand Up @@ -46,19 +47,25 @@ class ClipArtService : KoinComponent {
tempSparseArray.append(index, it)
}
}
val drawablesInStorage = getClipsFromStorage()
drawablesInStorage.forEach {
val drawablesInStorage = getClipsFromStorage().value
drawablesInStorage?.forEach {
tempSparseArray.append(++lastIndex, it.value)
}

return tempSparseArray
}

fun updateClipArts() {
storageClipArts.value = StorageUtils.getAllClips()
clipArts.value = getAllClips()
}

fun getClipArts(): LiveData<SparseArray<Drawable>> = clipArts

fun getClipsFromStorage() = StorageUtils.getAllClips()
fun getClipsFromStorage(): LiveData<HashMap<String, Drawable?>> = storageClipArts

fun deleteClipart(fileName: String) {
StorageUtils.deleteClipart(fileName)
updateClipArts()
}
}
2 changes: 2 additions & 0 deletions app/src/main/java/org/fossasia/badgemagic/di/Modules.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.fossasia.badgemagic.viewmodels.SettingsViewModel
import org.fossasia.badgemagic.viewmodels.DrawViewModel
import org.fossasia.badgemagic.viewmodels.DrawerViewModel
import org.fossasia.badgemagic.viewmodels.EditBadgeViewModel
import org.fossasia.badgemagic.viewmodels.EditClipartViewModel
import org.fossasia.badgemagic.viewmodels.SavedClipartViewModel
import org.koin.android.ext.koin.androidContext
import org.koin.androidx.viewmodel.dsl.viewModel
Expand All @@ -20,6 +21,7 @@ val viewModelModules = module {
viewModel { FilesViewModel(get()) }
viewModel { SettingsViewModel(get()) }
viewModel { EditBadgeViewModel(get()) }
viewModel { EditClipartViewModel(get()) }
viewModel { DrawViewModel(get()) }
viewModel { DrawerViewModel(get()) }
viewModel { SavedClipartViewModel(get()) }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.fossasia.badgemagic.ui

import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Observer
import kotlinx.android.synthetic.main.activity_edit_clipart.*
import org.fossasia.badgemagic.R
import org.fossasia.badgemagic.databinding.ActivityEditClipartBinding
import org.fossasia.badgemagic.util.Converters
import org.fossasia.badgemagic.util.StorageUtils
import org.fossasia.badgemagic.viewmodels.EditClipartViewModel
import org.koin.androidx.viewmodel.ext.android.viewModel

class EditClipartActivity : AppCompatActivity() {

private val editClipartViewModel by viewModel<EditClipartViewModel>()
private lateinit var fileName: String

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val activityDrawBinding = DataBindingUtil.setContentView<ActivityEditClipartBinding>(this, R.layout.activity_edit_clipart)
activityDrawBinding.viewModel = editClipartViewModel

if (intent.hasExtra("fileName")) {
fileName = intent?.extras?.getString("fileName") ?: ""
editClipartViewModel.drawingJSON.set(Converters.convertDrawableToLEDHex(StorageUtils.getClipartFromPath(fileName), false))
}

editClipartViewModel.savedButton.observe(this, Observer {
if (it) {
if (StorageUtils.saveEditedClipart(Converters.convertStringsToLEDHex(draw_layout.getCheckedList()), fileName)) {
Toast.makeText(this, R.string.clipart_saved_success, Toast.LENGTH_LONG).show()
editClipartViewModel.updateClipArts()
} else
Toast.makeText(this, R.string.clipart_saved_error, Toast.LENGTH_LONG).show()
finish()
}
})

editClipartViewModel.resetButton.observe(this, Observer {
if (it) {
draw_layout.resetCheckListWithDummyData()
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Observer
import org.fossasia.badgemagic.R
import org.fossasia.badgemagic.data.SavedClipart
import org.fossasia.badgemagic.databinding.FragmentSavedClipartsBinding
import org.fossasia.badgemagic.ui.base.BaseFragment
import org.fossasia.badgemagic.util.ImageUtils
import org.fossasia.badgemagic.viewmodels.SavedClipartViewModel
import org.koin.androidx.viewmodel.ext.android.viewModel

Expand All @@ -26,4 +29,14 @@ class SavedClipartFragment : BaseFragment() {
binding.viewModel = viewModel
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

viewModel.getStorageClipartLiveData().observe(viewLifecycleOwner, Observer { list ->
viewModel.adapter.setList(
list.map { SavedClipart(it.key, ImageUtils.convertToBitmap(it.value)) }
)
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import org.fossasia.badgemagic.util.ImageUtils
import org.fossasia.badgemagic.util.DRAWABLE_END
import org.fossasia.badgemagic.util.DRAWABLE_START
import org.fossasia.badgemagic.viewmodels.TextArtViewModel
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.koin.androidx.viewmodel.ext.android.sharedViewModel
import pl.droidsonroids.gif.GifImageView
import java.text.SimpleDateFormat
import java.util.Timer
Expand All @@ -74,7 +74,7 @@ class TextArtFragment : BaseFragment() {
private val drawableRecyclerAdapter = DrawableAdapter()
private val modeAdapter = ModeAdapter()

private val viewModel by viewModel<TextArtViewModel>()
private val viewModel by sharedViewModel<TextArtViewModel>()

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Expand Down Expand Up @@ -143,7 +143,7 @@ class TextArtFragment : BaseFragment() {
}
}

fun startSaveFile() {
private fun startSaveFile() {
textViewMainText.hideKeyboard()
showSaveFileDialog()
}
Expand Down
25 changes: 22 additions & 3 deletions app/src/main/java/org/fossasia/badgemagic/util/Converters.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const val DRAWABLE_START = '«'
const val DRAWABLE_END = '»'

object Converters {
private fun convertDrawableToLEDHex(drawableIcon: Drawable?, invertLED: Boolean): List<String> {
fun convertDrawableToLEDHex(drawableIcon: Drawable?, invertLED: Boolean): List<String> {
var bm = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888)
if (drawableIcon is VectorDrawable)
bm = ImageUtils.scaleBitmap(ImageUtils.vectorToBitmap(drawableIcon), 40)
Expand Down Expand Up @@ -185,22 +185,41 @@ object Converters {
val foundIndex = editable.indexOf(DRAWABLE_END, i)
i = if (foundIndex > 0) {
listOfArt.addAll(
convertDrawableToLEDHex(drawableSparse.get(editable.substring(i + 1, foundIndex).toInt()), invertLED)
handleInvertLED(convertDrawableToLEDHex(drawableSparse.get(editable.substring(i + 1, foundIndex).toInt()), invertLED), i == 0 && invertLED)
)
foundIndex + 1
} else {
editable.length
}
} else {
listOfArt.addAll(
convertTextToLEDHex(ch.toString(), invertLED).second
handleInvertLED(convertTextToLEDHex(ch.toString(), invertLED).second, i == 0 && invertLED)
)
i++
}
}
return listOfArt
}

private fun handleInvertLED(hexStrings: List<String>, addPrefix: Boolean): List<String> {
if (!addPrefix)
return hexStrings

val listNew = mutableListOf<String>()
if (checkValueInFirstColumn(hexStrings))
listNew.add("0101010101010101010101")
listNew.addAll(hexStrings)
return listNew
}

private fun checkValueInFirstColumn(hexStrings: List<String>): Boolean {
for (i in 0 until hexStrings[0].length step 2) {
if (BigInteger(hexStrings[0][i].toString(), 16).toString(10).toInt() < 8)
return true
}
return false
}

fun convertStringsToLEDHex(list: ArrayList<CheckList>): Bitmap {
val newBitmap = Bitmap.createBitmap(list[0].list.size, list.size, Bitmap.Config.ARGB_8888)
for (i in 0 until list.size) {
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/java/org/fossasia/badgemagic/util/StorageUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@ object StorageUtils {
return true
}

fun saveEditedClipart(bitmap: Bitmap, fileName: String): Boolean {
checkDirectory()
val file = File(EXTERNAL_CLIPART_DIRECTORY, fileName)
try {
val out = FileOutputStream(file)
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out)
out.flush()
out.close()
} catch (e: Exception) {
return false
}
return true
}

fun getAllClips(): HashMap<String, Drawable?> {
checkDirectory()
val list = HashMap<String, Drawable?>()
Expand All @@ -173,6 +187,10 @@ object StorageUtils {
return list
}

fun getClipartFromPath(filename: String): Drawable? {
return Drawable.createFromPath(File(EXTERNAL_CLIPART_DIRECTORY, filename).absolutePath)
}

fun deleteClipart(fileName: String) {
checkDirectory()
val deleteFile = File(EXTERNAL_CLIPART_DIRECTORY, fileName)
Expand Down
Loading

0 comments on commit 0eeff55

Please sign in to comment.