Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
yhao committed Sep 10, 2017
0 parents commit 518effa
Show file tree
Hide file tree
Showing 88 changed files with 3,098 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
19 changes: 19 additions & 0 deletions .idea/gradle.xml

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

33 changes: 33 additions & 0 deletions .idea/misc.xml

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

9 changes: 9 additions & 0 deletions .idea/modules.xml

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

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

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

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
54 changes: 54 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.yhao.firstkotlin"
minSdkVersion 15
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 {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
testCompile 'junit:junit:4.12'
//android
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:26.0.0-alpha1'
compile 'com.android.support:cardview-v7:26.0.0-alpha1'
//kotlin
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
//anko
compile "org.jetbrains.anko:anko-commons:$anko_version"
compile "org.jetbrains.anko:anko-coroutines:$anko_version"
//json解析
compile 'com.google.code.gson:gson:2.8.0'
//图片
compile 'com.github.bumptech.glide:glide:4.0.0'
compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.8'
//网络
compile 'com.squareup.okhttp3:okhttp:3.8.1'
compile 'com.squareup.okio:okio:1.13.0'
//日志
compile 'com.orhanobut:logger:2.1.1'
//进度
compile 'com.github.lzyzsd:circleprogress:1.2.1'
}
25 changes: 25 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /home/yhao/Android/Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.yhao.module

import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumentation test, which will execute on an Android device.
*
* @see [Testing documentation](http://d.android.com/tools/testing)
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
@Throws(Exception::class)
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()
assertEquals("com.yhao.firstkotlin", appContext.packageName)
}
}
31 changes: 31 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yhao.module">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
android:name="com.yhao.commen.App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".BigPicActivity" />
<activity android:name=".BootActivity" />
<activity android:name=".AboutAppActivity"/>
</application>

</manifest>
22 changes: 22 additions & 0 deletions app/src/main/java/com/yhao/commen/App.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.yhao.commen

import android.app.Application
import com.yhao.commen.notNullSingleValue

/**
* Created by yhao on 17-9-4.
*
*/

class App : Application() {


companion object {
var instance: App by notNullSingleValue()
}

override fun onCreate() {
super.onCreate()
instance = this
}
}
32 changes: 32 additions & 0 deletions app/src/main/java/com/yhao/commen/Const.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.yhao.commen

import android.os.Environment
import java.io.File

/**
* Created by yhao on 17-9-6.
*
*/

class Const {
companion object {

private val yiyuan_appid = "45578"
private val yiyuan_secret = "4e6e7a13e16a42059a75a9a8931a779f"
private val yiyuanAuth = "&showapi_sign=$yiyuan_secret&showapi_appid=$yiyuan_appid"

fun buildUrl(url: String): String {
return "$url&$yiyuanAuth"
}

val ROOT_DIR: String by lazy {
val path = Environment.getExternalStorageDirectory().absolutePath + "/ForYourSmile/"
val file = File(path)
if (!file.exists()) {
file.mkdirs()
}
path
}

}
}
80 changes: 80 additions & 0 deletions app/src/main/java/com/yhao/commen/DelegateExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.yhao.commen

import android.annotation.SuppressLint
import android.content.Context
import android.content.SharedPreferences
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty

/**
* Created by yhao on 17-9-4.
* 扩展委托
*/


/**
* * notNull委托,只能被赋值一次,如果第二次赋值就会抛异常
*/
fun <T> notNullSingleValue():
ReadWriteProperty<Any?, T> = NotNullSingleValueVar()

/**
* SharedPreferences 委托 自动存取
*/
fun <T : Any> preference(context: Context, name: String, default: T):
ReadWriteProperty<Any?, T> = Preference(context, name, default)


private class NotNullSingleValueVar<T> : ReadWriteProperty<Any?, T> {
private var value: T? = null
override fun getValue(thisRef: Any?, property: KProperty<*>): T {
return value ?: throw IllegalStateException("not initialized")
}

override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
this.value = if (this.value == null) value
else throw IllegalStateException("already initialized")
}
}


private class Preference<T>(val context: Context, val name: String, val default: T)
: ReadWriteProperty<Any?, T> {

val prefs: SharedPreferences by lazy {
context.getSharedPreferences("default", Context.MODE_PRIVATE)
}

override fun getValue(thisRef: Any?, property: KProperty<*>): T {
return findPreference(name, default)
}

override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
putPreference(name, value)
}

private fun <T> findPreference(name: String, default: T): T = with(prefs) {
val res: Any = when (default) {
is Long -> getLong(name, default)
is String -> getString(name, default)
is Int -> getInt(name, default)
is Boolean -> getBoolean(name, default)
is Float -> getFloat(name, default)
else -> throw IllegalArgumentException("This type can not be saved into Preferences")
}
res as T
}

@SuppressLint("CommitPrefEdits")
private fun <U> putPreference(name: String, value: U) = with(prefs.edit()) {
when (value) {
is Long -> putLong(name, value)
is String -> putString(name, value)
is Int -> putInt(name, value)
is Boolean -> putBoolean(name, value)
is Float -> putFloat(name, value)
else -> throw IllegalArgumentException("This type can be saved into Preferences")
}.apply()
}

}
Loading

0 comments on commit 518effa

Please sign in to comment.