v1.0.1 release

This commit is contained in:
Jay 2017-07-06 17:43:52 +08:00
parent c110c52301
commit e07cb6909f
21 changed files with 585 additions and 66 deletions

View File

@ -2,6 +2,7 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/BuyWhat.iml" filepath="$PROJECT_DIR$/BuyWhat.iml" />
<module fileurl="file://C:\Project\BuyWhatNative\BuyWhat.iml" filepath="C:\Project\BuyWhatNative\BuyWhat.iml" />
<module fileurl="file://$PROJECT_DIR$/BuyWhatNative.iml" filepath="$PROJECT_DIR$/BuyWhatNative.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />

View File

@ -11,14 +11,25 @@ android {
applicationId "xyz.mtfos.buywhat"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
versionCode 4
versionName "1.0.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
signingConfigs {
release {
storeFile file("${rootDir}/mtfos")
storePassword "pass.ok=1"
keyAlias "mtfos"
keyPassword "pass.ok=1"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
}

View File

@ -6,9 +6,9 @@
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:roundIcon="@drawable/logo"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
@ -19,6 +19,7 @@
</intent-filter>
</activity>
<activity android:name=".StoreList" />
<activity android:name=".ItemRandom" />
</application>
</manifest>

View File

@ -0,0 +1,223 @@
package xyz.mtfos.buywhat
import android.annotation.SuppressLint
import android.content.Context
import android.os.Bundle
import android.os.Handler
import android.os.Message
import android.view.View
import android.view.ViewGroup
import android.widget.*
import org.json.JSONArray
import org.json.JSONObject
import xyz.mtfos.tools.apiObject
import xyz.mtfos.tools.objectTool.bind
import java.util.*
import kotlin.collections.ArrayList
/**
* Created by jay on 2017/7/6.
*/
class ItemRandom : SampleActivity() {
private val tvTitle: TextView by bind(R.id.tvTitle)
private val ivRefresh: ImageView by bind(R.id.ivRefresh)
private val lvCommodity: ListView by bind(R.id.lvCommodity)
private var store_id: Int? = null
private var itemList: ArrayList<JSONObject> = ArrayList()
private var adapter: lvAdapter? = null
private val rangeMin: EditText by bind(R.id.rangeMin)
private val rangeMax: EditText by bind(R.id.rangeMax)
private val btnRandom: Button by bind(R.id.btnRandom)
private val tvResult: TextView by bind(R.id.tvResult)
private val ivBack: ImageView by bind(R.id.ivBack)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setViewSource(R.layout.activity_item_random)
tvTitle?.text = intent?.getStringExtra("name")
store_id = intent?.getIntExtra("id", 0)
adapter = lvAdapter(this@ItemRandom, 0)
lvCommodity.adapter = adapter
lvCommodity.setOnItemClickListener({parent, view, position, id ->
val data: JSONObject = itemList.get(position) as JSONObject
var sk:Boolean = data!!["skip"] as Boolean
data?.put("skip", !sk)
itemList.set(position, data)
adapter?.notifyDataSetChanged()
randomItem()
})
btnRandom.setOnClickListener{v->
val json : JSONObject? = randomItem()
val str : String = if(json != null) {
"Result : ${json!!["name"]} $${json!!["price"]}"
}else{
"Result : 目標區間無商品"
}
tvResult.text = str
}
ivRefresh.setOnClickListener({ v ->
getList()
})
ivBack.setOnClickListener({ v ->
finish()
})
getList()
}
fun getList() {
if(store_id == 0 || store_id == null) return
resetView()
toggleLoading(true)
api.getItems(store_id!!, object: apiObject.apicb{
override fun Callback(json: JSONObject?) {
uiHandler.post { toggleLoading(false) }
if(json!!["status"] == 1) {
val jarr :JSONArray = json!!["record"] as JSONArray
itemList.clear()
if(jarr.length() > 0) {
uiHandler.sendEmptyMessage(3)
for(i in 0..(jarr.length() - 1)){
val tmp: JSONObject =jarr!![i] as JSONObject
tmp.put("skip", false)
itemList.add(tmp)
}
}else{
uiHandler.sendEmptyMessage(2)
}
uiHandler.sendEmptyMessage(1)
}
}
})
}
fun resetView () {
rangeMin.setText("0")
rangeMax.setText("0")
tvResult.text = ""
}
fun randomItem (): JSONObject? {
val min: String = rangeMin.text.toString()
val max: String = rangeMax.text.toString()
var imin = if(min.toIntOrNull() == null) 0 else min.toInt()
var imax = if(max.toIntOrNull() == null) 0 else max.toInt()
val tmp: ArrayList<JSONObject> = ArrayList()
for(i in 0..(itemList.size - 1)){
val t:JSONObject = itemList[i]
var flag:Boolean = false
val price:Int = t!!["price"] as Int
if(t!!["skip"] == false){
if(imin == 0 && imax == 0){
flag = true
}else if(imin > 0 && imax == 0){
if(price >= imin){
flag = true
}
}else if(imin == 0 && imax > 0) {
if(price <= imax) {
flag = true
}
}else{
if(price in imin..imax) {
flag = true
}
}
}
if(flag){
tmp.add(t)
}
}
var arr: Array<JSONObject> = tmp.toTypedArray()
if(arr.isNotEmpty()) {
arr = shuffleArray(arr) as Array<JSONObject>
}
return if(arr.isNotEmpty()) {
arr[0]
} else {
null
}
}
fun shuffleArray(arr: Array<JSONObject>) : Array<JSONObject>{
var tmp = arr
var rand: Random = Random()
var limit: Int = 0
while (limit < 2) {
for (i in 0..(tmp.size - 1)) {
val pos: Int = rand.nextInt(tmp.size)
val a = tmp[pos]
tmp[pos] = tmp[i]
tmp[i] = a
}
limit ++
}
return tmp
}
@SuppressLint("HandlerLeak")
private val uiHandler = object : Handler() {
override fun handleMessage(msg: Message?) {
super.handleMessage(msg)
when (msg!!.what) {
1 -> {
// update listview data
adapter!!.clear()
adapter!!.addAll(itemList)
}
2 -> {
btnRandom.isClickable = false
}
3 -> {
btnRandom.isClickable = true
}
}
}
}
class lvAdapter(context: Context, resource: Int) : ArrayAdapter<JSONObject>(context, resource) {
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
val data = getItem(position) as JSONObject
var v: View = if (convertView == null) {
View.inflate(context, R.layout.listview_commodity_item, null)
} else {
convertView
}
val tvSkip: TextView = v.findViewById<TextView>(R.id.tvSkip)
tvSkip.text = if(data!!["skip"] == false){
context.getString(R.string.commodity_no_skip)
}else{
context.getString(R.string.commodity_skip)
}
val tv: TextView = v.findViewById(R.id.tvItem)
val name:String = data!!["name"] as String
val price:Int = data!!["price"] as Int
tv.text = "${name} $${price}"
return v
}
}
}

View File

@ -0,0 +1,45 @@
package xyz.mtfos.buywhat
import android.app.Activity
import android.os.Handler
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.RelativeLayout
import xyz.mtfos.tools.apiObject
import xyz.mtfos.tools.objectTool.bind
/**
* Created by jay on 2017/7/6.
*/
open class SampleActivity : Activity() {
protected val api: apiObject = apiObject(this@SampleActivity)
protected val layMain: RelativeLayout by bind(R.id.layMain)
protected val layLoading: LinearLayout by bind(R.id.layLoading)
fun setViewSource(v: View?) {
setContentView(v)
setDynView()
}
fun setViewSource(v: Int) {
setContentView(v)
setDynView()
}
fun setDynView() {
val loadingItem: LinearLayout = layoutInflater.inflate(R.layout.lay_loading, null) as LinearLayout
loadingItem.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
layLoading?.addView(loadingItem)
}
fun toggleLoading(flag: Boolean) {
layLoading?.visibility = if (flag == true) {
View.VISIBLE
} else {
View.GONE
}
}
}

View File

@ -1,7 +1,6 @@
package xyz.mtfos.buywhat
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
@ -18,28 +17,28 @@ import xyz.mtfos.tools.objectTool.bind
/**
* Created by jay on 2017/7/5.
*/
class StoreList : Activity() {
class StoreList : SampleActivity() {
private val lv: ListView by bind(R.id.storelv)
private val tvTitle: TextView by bind(R.id.tvTitle)
private val ivRefresh: ImageView by bind(R.id.ivRefresh)
private val api: apiObject = apiObject(this@StoreList)
private var storeList: ArrayList<JSONObject> = ArrayList()
private var adapter: lvAdapter? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_store_list)
setViewSource(R.layout.activity_store_list)
adapter = lvAdapter(this@StoreList, 0)
lv.adapter = adapter
lv.setOnItemClickListener({parent, view, position, id ->
lv.setOnItemClickListener({ parent, view, position, id ->
val data: JSONObject = storeList.get(position) as JSONObject
val sid: Int = data!!["id"] as Int
val name: String = data!!["name"] as String
var intent = Intent(this@StoreList, null)
val intent = Intent(this@StoreList, ItemRandom::class.java)
intent.putExtra("id", sid)
intent.putExtra("name", name)
startActivity(intent)
})
@ -51,13 +50,15 @@ class StoreList : Activity() {
}
fun getList() {
toggleLoading(true)
api.getStore(object : apiObject.apicb {
override fun Callback(json: JSONObject?) {
uiHandler.post({ toggleLoading(false) })
if (json!!["status"] == 1) {
var jarr: JSONArray = json!!["record"] as JSONArray
if(jarr.length() > 0) {
storeList.clear()
for(i in 0..(jarr.length() - 1)) {
storeList.clear()
if (jarr.length() > 0) {
for (i in 0..(jarr.length() - 1)) {
val tmp = jarr.getJSONObject(i)
storeList.add(tmp)
}
@ -82,13 +83,13 @@ class StoreList : Activity() {
}
}
class lvAdapter(context: Context, resource: Int): ArrayAdapter<JSONObject>(context, resource) {
class lvAdapter(context: Context, resource: Int) : ArrayAdapter<JSONObject>(context, resource) {
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
val data = getItem(position) as JSONObject
var v: View = if(convertView == null) {
var v: View = if (convertView == null) {
View.inflate(context, R.layout.listview_store_item, null)
}else {
} else {
convertView
}
val tv: TextView = v.findViewById(R.id.tvItem)

View File

@ -37,7 +37,7 @@ open class apiObject constructor(val ctx: Context) {
open fun getItems(storeId: Int, cb: apicb) {
val url:String = "${projectSet.apiUrl}/item/${storeId}"
var req:Request = Request.Builder()
val req:Request = Request.Builder()
.url(url)
.build()
send(req, object : apicb {

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 215 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -0,0 +1,166 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layMain"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/header_height"
android:orientation="horizontal">
<LinearLayout
android:layout_width="30dp"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/ivBack"
android:layout_width="25dp"
android:layout_height="25dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_keyboard_arrow_left_black_24dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:layout_width="30dp"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/ivRefresh"
android:layout_width="25dp"
android:layout_height="25dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_refresh_black_24dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="130dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tv_price_range"
android:textSize="15dp" />
<EditText
android:id="@+id/rangeMin"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:gravity="center"
android:inputType="numberDecimal"
android:text="0" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="~"
android:textSize="15dp" />
<EditText
android:id="@+id/rangeMax"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:gravity="center"
android:inputType="numberDecimal"
android:text="0" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="@+id/btnRandom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/btn_random"
android:textAllCaps="false"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/tvResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="#89000000"></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/commodity_list"
android:textSize="20dp" />
<ListView
android:id="@+id/lvCommodity"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/layLoading"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone" />
</RelativeLayout>

View File

@ -1,58 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLayout"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="30dp"
android:layout_height="match_parent"
android:orientation="vertical"></LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/store_title"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:layout_width="30dp"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/ivRefresh"
android:layout_width="25dp"
android:layout_height="25dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_refresh_black_24dp"/>
</LinearLayout>
</LinearLayout>
android:id="@+id/layMain">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/storelv"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="@dimen/header_height"
android:orientation="horizontal">
<LinearLayout
android:layout_width="30dp"
android:layout_height="match_parent"
android:orientation="vertical"></LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/store_title"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:layout_width="30dp"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/ivRefresh"
android:layout_width="25dp"
android:layout_height="25dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_refresh_black_24dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/storelv"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/layLoading"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:visibility="gone"/>
</RelativeLayout>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#33000000"
android:gravity="center">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="60dp"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dp"
android:id="@+id/tvSkip"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="20dp">
<TextView
android:id="@+id/tvItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Simple"
android:textSize="20dp" />
</LinearLayout>
</LinearLayout>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="header_height">35dp</dimen>
</resources>

View File

@ -1,4 +1,9 @@
<resources>
<string name="app_name">BuyWhat</string>
<string name="app_name">買什麼</string>
<string name="store_title">商店列表</string>
<string name="commodity_list">商品列表</string>
<string name="commodity_skip">忽略</string>
<string name="commodity_no_skip">不忽略</string>
<string name="tv_price_range">價格區間</string>
<string name="btn_random">Random!!</string>
</resources>

View File

@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.1.3'
ext.kotlin_version = '1.1.3-2'
repositories {
google()
jcenter()

BIN
mtfos Normal file

Binary file not shown.