Skip to content

Commit

Permalink
Merge branch 'saran_work'
Browse files Browse the repository at this point in the history
  • Loading branch information
saran2020 committed Aug 14, 2018
2 parents fcb57b9 + ec5d955 commit bac184d
Show file tree
Hide file tree
Showing 64 changed files with 1,196 additions and 841 deletions.
File renamed without changes.
79 changes: 79 additions & 0 deletions RealmBrowser/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'realm-android'
apply plugin: 'kotlin-kapt'

ext {
bintrayRepo = 'RealmBrowser'
bintrayName = 'com.github.saran2020.realmbrowser'

libraryName = 'RealmBrowser'

publishedGroupId = 'com.github.saran2020.realmbrowser'
artifact = 'RealmBrowser'
libraryVersion = '0.1'

libraryDescription = 'A database browser for Android to browse Realm database'

siteUrl = 'https://github.com/saran2020/RealmBrowser'
gitUrl = 'https://github.com/saran2020/RealmBrowser.git'

developerId = 'saran2020'
developerName = 'Saran Sankaran'
developerEmail = '[email protected]'

licenseName = 'The Apache Software License, Version 2.0'
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
allLicenses = ["Apache-2.0"]
}

android {
compileSdkVersion 26
buildToolsVersion "27.0.3"

defaultConfig {
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation "com.android.support:appcompat-v7:$support_library"
implementation "com.android.support:recyclerview-v7:$support_library"
implementation "com.xiaofeng.android:flowlayoutmanager:$flow_layout_manager"

// Test dependencies
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

repositories {
mavenCentral()
}

//Add these lines to publish library to bintray. This is the readymade scripts made by github user nuuneoi to make uploading to bintray easy.
//Place it at the end of the file
if (project.rootProject.file('local.properties').exists()) {
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
}

subprojects {
tasks.withType(Javadoc).all { enabled = false }
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.github.saran2020.realmbrowser

import android.content.Context
import android.content.Intent
import com.github.saran2020.realmbrowser.data.model.ObjectType
import io.realm.RealmFieldType

/**
* Helper class to store activity related stuff
* Created by Saran on 14-Jan-18.
*/
fun startResultActivity(context: Context, className: String, find: Byte) {
val intent = Intent(context, ResultActivity::class.java)
intent.putExtra(EXTRA_CLASS_NAME, className)
intent.putExtra(EXTRA_FIND, find)
context.startActivity(intent)
}

fun startResultActivity(context: Context, data: ObjectType) {
val intent = Intent(context, ResultActivity::class.java)

val objectInfo = data.objectInfo

intent.putExtra(EXTRA_CLASS_NAME, objectInfo.parentClassName)
intent.putExtra(EXTRA_PARENT_PRIMARY_KEY_NAME, objectInfo.parentPrimaryKeyFieldName)
intent.putExtra(EXTRA_PARENT_PRIMARY_KEY_TYPE, objectInfo.parentPrimaryKeyType)
intent.putExtra(EXTRA_KEY_FIELD_GETTER_NAME, objectInfo.fieldGetterName)
intent.putExtra(EXTRA_KEY_FIELD_NAME, objectInfo.fieldName)
intent.putExtra(EXTRA_KEY_FIELD_TYPE, objectInfo.fieldType)

// check type and insert value
when (objectInfo.parentPrimaryKeyType) {
RealmFieldType.BOOLEAN.nativeValue -> intent.putExtra(EXTRA_PARENT_PRIMARY_KEY_VALUE, objectInfo.parentPrimaryKeyValue as Boolean)
RealmFieldType.FLOAT.nativeValue -> intent.putExtra(EXTRA_PARENT_PRIMARY_KEY_VALUE, objectInfo.parentPrimaryKeyValue as Float)
RealmFieldType.DOUBLE.nativeValue -> intent.putExtra(EXTRA_PARENT_PRIMARY_KEY_VALUE, objectInfo.parentPrimaryKeyValue as Double)

RealmFieldType.STRING.nativeValue -> {
intent.putExtra(EXTRA_PARENT_PRIMARY_KEY_VALUE, objectInfo.parentPrimaryKeyValue as String)
}

RealmFieldType.INTEGER.nativeValue -> {
when (objectInfo.parentPrimaryKeyValue) {
is Long -> intent.putExtra(EXTRA_PARENT_PRIMARY_KEY_VALUE, objectInfo.parentPrimaryKeyValue)
is Int -> intent.putExtra(EXTRA_PARENT_PRIMARY_KEY_VALUE, objectInfo.parentPrimaryKeyValue)
is Short -> intent.putExtra(EXTRA_PARENT_PRIMARY_KEY_VALUE, objectInfo.parentPrimaryKeyValue)
is Byte -> intent.putExtra(EXTRA_PARENT_PRIMARY_KEY_VALUE, objectInfo.parentPrimaryKeyValue)
else -> ERROR_TEXT
}
}
}

intent.putExtra(EXTRA_FIND, FIND_FIRST)

context.startActivity(intent)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@file:JvmName("Constants")

package com.github.saran2020.realmbrowser

/**
Expand All @@ -11,6 +12,14 @@ const val NO_ITEM_SELECTED: Byte = -1
const val EXTRA_CLASS_NAME = "EXTRA_CLASS_NAME"
const val EXTRA_FIND = "EXTRA_FIND"

const val EXTRA_PARENT_PRIMARY_KEY_NAME = "EXTRA_PARENT_PRIMARY_KEY_NAME"
const val EXTRA_PARENT_PRIMARY_KEY_TYPE = "EXTRA_PARENT_PRIMARY_KEY_TYPE"
const val EXTRA_PARENT_PRIMARY_KEY_VALUE = "EXTRA_PARENT_PRIMARY_KEY_VALUE"
const val EXTRA_KEY_FIELD_GETTER_NAME = "EXTRA_KEY_FIELD_GETTER_NAME"
const val EXTRA_KEY_FIELD_NAME = "EXTRA_KEY_FIELD_NAME"
const val EXTRA_KEY_FIELD_TYPE = "EXTRA_KEY_FIELD_TYPE"
const val EXTRA_PARENT_PRIMARY_KEY_GETTER_NAME = "EXTRA_PARENT_PRIMARY_KEY_GETTER_NAME"

// Query Types
const val QUERY_EQUAL_TO: Byte = 50

Expand Down Expand Up @@ -44,4 +53,10 @@ const val TYPE_REALM_OBJECT: Byte = -12
const val GETTER_PREFIX = "get"
const val BOOLEAN_GETTER_PREFIX = "is"

const val ERROR_TEXT = "Some error occurred"
const val ERROR_TEXT = "Some error occurred"

// result types
const val RESULT_TYPE_EMPTY:Byte = 110
const val RESULT_TYPE_OBJECT:Byte = 111
const val RESULT_TYPE_LIST:Byte = 112
const val RESULT_TYPE_REALM_RESULT:Byte = 113
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.github.saran2020.realmbrowser

import android.content.Context
import android.support.v4.content.res.ResourcesCompat
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView

/**
* Created by Saran on 11-Nov-17.
*/
class FindAdapter(private var context: Context, private var itemList: List<String>) : RecyclerView.Adapter<FindAdapter.ViewHolder>() {

private val inflator = LayoutInflater.from(context)

var selectedItem = NO_ITEM_SELECTED

override fun getItemCount() = itemList.size

override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
val view = inflator.inflate(R.layout.chip_find_item, parent, false)
return ViewHolder(view as TextView)
}

override fun onBindViewHolder(holder: ViewHolder?, position: Int) {
holder?.textView?.text = itemList[position]
}

private fun setSelectedItem(textView: TextView, position: Int) {

val selectedPosition: Byte = when (position) {
0 -> FIND_ALL
1 -> FIND_FIRST
else -> NO_ITEM_SELECTED
}

selectedItem = if (selectedPosition == selectedItem)
NO_ITEM_SELECTED
else
selectedPosition

if (selectedItem == NO_ITEM_SELECTED) {

// No item selected, set it back to default
val defaultBackGround = ResourcesCompat.getDrawable(context.resources, R.drawable.background_chip, null)
textView.background = defaultBackGround

val textColor = ResourcesCompat.getColor(context.resources, R.color.findTextColor, null)
textView.setTextColor(textColor)
} else {

// Item selected, set selected color
val selectedColor = ResourcesCompat.getColor(context.resources, R.color.colorPrimary, null)
textView.setBackgroundColor(selectedColor)

val textColor = ResourcesCompat.getColor(context.resources, R.color.buttonTextColor, null)
textView.setTextColor(textColor)
}
}

inner class ViewHolder(val textView: TextView) : RecyclerView.ViewHolder(textView) {


private var cancelOnClickListener = View.OnClickListener {
val position = adapterPosition
setSelectedItem(it as TextView, position)
}

init {
textView.setOnClickListener(cancelOnClickListener)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.github.saran2020.realmbrowser

import android.content.DialogInterface
import android.os.Bundle
import android.support.v7.app.AlertDialog
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.RecyclerView
import android.text.Editable
import android.text.TextWatcher
import android.view.View
import android.widget.*
import com.xiaofeng.flowlayoutmanager.FlowLayoutManager
Expand All @@ -19,14 +19,12 @@ class MainActivity : AppCompatActivity() {
private val TAG = MainActivity::class.java.simpleName

// global var
lateinit var appPackageName: String
lateinit var realm: Realm
private lateinit var recyclerQueryAdapter: QueryAdapter
private lateinit var recyclerFindAdapter: FindAdapter

//views
private lateinit var editClassName: EditText
private lateinit var textPackageName: TextView
private lateinit var imageAddQuery: ImageView
private lateinit var recyclerQueryContent: RecyclerView
private lateinit var recyclerFindContent: RecyclerView
Expand All @@ -40,18 +38,14 @@ class MainActivity : AppCompatActivity() {

realm = Realm.getDefaultInstance()

appPackageName = applicationContext.packageName

// views
editClassName = findViewById(R.id.editClassName_library)
textPackageName = findViewById(R.id.packageName_library)
imageAddQuery = findViewById(R.id.queryAdd_library)
recyclerQueryContent = findViewById(R.id.queryRecycler_library)
recyclerFindContent = findViewById(R.id.findRecycler_library)
textQuery = findViewById(R.id.query_library)
buttonFetch = findViewById(R.id.buttonFetch_library)

editClassName.addTextChangedListener(textChangeListener)
imageAddQuery.setOnClickListener(onAddQueryClickListener)
buttonFetch.setOnClickListener(onFetchClickListener)

Expand All @@ -61,9 +55,13 @@ class MainActivity : AppCompatActivity() {
recyclerQueryContent.adapter = recyclerQueryAdapter

// find recycler
recyclerFindAdapter = FindAdapter(getFindItems())
recyclerFindAdapter = FindAdapter(this, getFindItems())
recyclerFindContent.layoutManager = FlowLayoutManager()
recyclerFindContent.adapter = recyclerFindAdapter

editClassName.setOnClickListener {
showModelPicker()
}
}

override fun onDestroy() {
Expand All @@ -81,29 +79,34 @@ class MainActivity : AppCompatActivity() {
FIND_FIRST_STRING)
}

// listeners
private var textChangeListener = object : TextWatcher {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}
override fun afterTextChanged(s: Editable?) {
if (s?.isEmpty() == true) textPackageName.text = ""
textPackageName.text = String.format("%s.%s", appPackageName, s)
private fun showModelPicker() {

val classes = realm.configuration.realmObjectClasses
.map { it.simpleName as CharSequence }
.toTypedArray()

val listener = DialogInterface.OnClickListener { _, which ->
editClassName.setText(classes[which])
}

AlertDialog.Builder(this)
.setTitle("Pick a Model")
.setItems(classes, listener).show()
}

private val onAddQueryClickListener = View.OnClickListener {
Toast.makeText(this@MainActivity, "Add Clicked", Toast.LENGTH_SHORT).show()
Toast.makeText(this@MainActivity, "Coming soon", Toast.LENGTH_SHORT).show()
}

private var onFetchClickListener = View.OnClickListener {

var fullClassName = textPackageName.text.toString()
if (fullClassName.isEmpty()) return@OnClickListener
val className = editClassName.text.toString()
if (className.isEmpty()) return@OnClickListener

when (this@MainActivity.recyclerFindAdapter.selectedItem) {
NO_ITEM_SELECTED -> this@MainActivity.recyclerFindAdapter.selectedItem
FIND_ALL -> ResultActivity.startActivity(this, fullClassName, FIND_ALL)
FIND_FIRST -> ResultActivity.startActivity(this, fullClassName, FIND_FIRST)
FIND_ALL -> startResultActivity(this, className, FIND_ALL)
FIND_FIRST -> startResultActivity(this, className, FIND_FIRST)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.github.saran2020.realmbrowser.model.QueryItem
import com.github.saran2020.realmbrowser.data.model.QueryItem

/**
* Created by its me on 11-Nov-17.
* Created by Saran on 11-Nov-17.
*/
class QueryAdapter : RecyclerView.Adapter<QueryAdapter.ViewHolder>() {

Expand Down
Loading

0 comments on commit bac184d

Please sign in to comment.