repo_name
stringlengths 7
104
| file_path
stringlengths 13
198
| context
stringlengths 67
7.15k
| import_statement
stringlengths 16
4.43k
| code
stringlengths 40
6.98k
| prompt
stringlengths 227
8.27k
| next_line
stringlengths 8
795
|
---|---|---|---|---|---|---|
martino2k6/StoreBox
|
storebox-lib/src/main/java/net/orange_box/storebox/StoreBox.java
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/enums/PreferencesMode.java
// public enum PreferencesMode {
//
// /**
// * Default.
// *
// * @see android.content.Context#MODE_PRIVATE
// */
// MODE_PRIVATE(Context.MODE_PRIVATE),
//
// /**
// * @see android.content.Context#MODE_MULTI_PROCESS
// */
// MODE_MULTI_PROCESS(Context.MODE_MULTI_PROCESS),
//
// /**
// * @see android.content.Context#MODE_WORLD_READABLE
// */
// @Deprecated
// MODE_WORLD_READABLE(Context.MODE_WORLD_READABLE),
//
// /**
// * @see android.content.Context#MODE_WORLD_WRITEABLE
// */
// @Deprecated
// MODE_WORLD_WRITEABLE(Context.MODE_WORLD_WRITEABLE);
//
// private final int value;
//
// private PreferencesMode(int value) {
// this.value = value;
// }
//
// public int value() {
// return value;
// }
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/enums/PreferencesType.java
// public enum PreferencesType {
//
// /**
// * Default.
// *
// * @see net.orange_box.storebox.annotations.type.DefaultSharedPreferences
// * @see android.preference.PreferenceManager#getDefaultSharedPreferences(
// * android.content.Context)
// */
// DEFAULT_SHARED,
//
// /**
// * @see net.orange_box.storebox.annotations.type.ActivityPreferences
// * @see android.app.Activity#getPreferences(int)
// */
// ACTIVITY,
//
// /**
// * @see net.orange_box.storebox.annotations.type.FilePreferences
// * @see android.content.Context#getSharedPreferences(String, int)
// */
// FILE
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/enums/SaveMode.java
// public enum SaveMode {
//
// /**
// * Default.
// *
// * @see android.content.SharedPreferences.Editor#apply()
// */
// APPLY,
//
// /**
// * @see android.content.SharedPreferences.Editor#commit()
// */
// COMMIT,
//
// /**
// * {@link android.content.SharedPreferences.Editor#apply()} or
// * {@link android.content.SharedPreferences.Editor#commit()} will have
// * to be called explicitly.
// */
// NOME
// }
|
import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import net.orange_box.storebox.annotations.option.SaveOption;
import net.orange_box.storebox.annotations.type.ActivityPreferences;
import net.orange_box.storebox.annotations.type.DefaultSharedPreferences;
import net.orange_box.storebox.annotations.type.FilePreferences;
import net.orange_box.storebox.enums.PreferencesMode;
import net.orange_box.storebox.enums.PreferencesType;
import net.orange_box.storebox.enums.SaveMode;
import java.lang.reflect.Proxy;
import java.util.Locale;
|
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox;
/**
* Creates a no-thrills instance of the supplied interface, by reading any
* options provided through interface-level annotations.
* <p>
* If you'd like to provide options dynamically at run-time, take a look at
* {@link Builder}.
*/
public final class StoreBox {
/**
* @param context - the context under which the
* {@link android.content.SharedPreferences} should be opened
* @param cls - the interface class which should be instantiated
* @return new instance of class {@code cls} using {@code context}
*/
public static <T> T create(Context context, Class<T> cls) {
return new Builder<>(context, cls).build();
}
private StoreBox() {}
/**
* Can be used to provide a customised instance of the supplied interface,
* by setting custom options through builder methods.
*
* @param <T>
*/
public static final class Builder<T> {
private final Context context;
private final Class<T> cls;
private PreferencesType preferencesType = PreferencesType.DEFAULT_SHARED;
private String preferencesName = "";
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/enums/PreferencesMode.java
// public enum PreferencesMode {
//
// /**
// * Default.
// *
// * @see android.content.Context#MODE_PRIVATE
// */
// MODE_PRIVATE(Context.MODE_PRIVATE),
//
// /**
// * @see android.content.Context#MODE_MULTI_PROCESS
// */
// MODE_MULTI_PROCESS(Context.MODE_MULTI_PROCESS),
//
// /**
// * @see android.content.Context#MODE_WORLD_READABLE
// */
// @Deprecated
// MODE_WORLD_READABLE(Context.MODE_WORLD_READABLE),
//
// /**
// * @see android.content.Context#MODE_WORLD_WRITEABLE
// */
// @Deprecated
// MODE_WORLD_WRITEABLE(Context.MODE_WORLD_WRITEABLE);
//
// private final int value;
//
// private PreferencesMode(int value) {
// this.value = value;
// }
//
// public int value() {
// return value;
// }
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/enums/PreferencesType.java
// public enum PreferencesType {
//
// /**
// * Default.
// *
// * @see net.orange_box.storebox.annotations.type.DefaultSharedPreferences
// * @see android.preference.PreferenceManager#getDefaultSharedPreferences(
// * android.content.Context)
// */
// DEFAULT_SHARED,
//
// /**
// * @see net.orange_box.storebox.annotations.type.ActivityPreferences
// * @see android.app.Activity#getPreferences(int)
// */
// ACTIVITY,
//
// /**
// * @see net.orange_box.storebox.annotations.type.FilePreferences
// * @see android.content.Context#getSharedPreferences(String, int)
// */
// FILE
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/enums/SaveMode.java
// public enum SaveMode {
//
// /**
// * Default.
// *
// * @see android.content.SharedPreferences.Editor#apply()
// */
// APPLY,
//
// /**
// * @see android.content.SharedPreferences.Editor#commit()
// */
// COMMIT,
//
// /**
// * {@link android.content.SharedPreferences.Editor#apply()} or
// * {@link android.content.SharedPreferences.Editor#commit()} will have
// * to be called explicitly.
// */
// NOME
// }
// Path: storebox-lib/src/main/java/net/orange_box/storebox/StoreBox.java
import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import net.orange_box.storebox.annotations.option.SaveOption;
import net.orange_box.storebox.annotations.type.ActivityPreferences;
import net.orange_box.storebox.annotations.type.DefaultSharedPreferences;
import net.orange_box.storebox.annotations.type.FilePreferences;
import net.orange_box.storebox.enums.PreferencesMode;
import net.orange_box.storebox.enums.PreferencesType;
import net.orange_box.storebox.enums.SaveMode;
import java.lang.reflect.Proxy;
import java.util.Locale;
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox;
/**
* Creates a no-thrills instance of the supplied interface, by reading any
* options provided through interface-level annotations.
* <p>
* If you'd like to provide options dynamically at run-time, take a look at
* {@link Builder}.
*/
public final class StoreBox {
/**
* @param context - the context under which the
* {@link android.content.SharedPreferences} should be opened
* @param cls - the interface class which should be instantiated
* @return new instance of class {@code cls} using {@code context}
*/
public static <T> T create(Context context, Class<T> cls) {
return new Builder<>(context, cls).build();
}
private StoreBox() {}
/**
* Can be used to provide a customised instance of the supplied interface,
* by setting custom options through builder methods.
*
* @param <T>
*/
public static final class Builder<T> {
private final Context context;
private final Class<T> cls;
private PreferencesType preferencesType = PreferencesType.DEFAULT_SHARED;
private String preferencesName = "";
|
private PreferencesMode preferencesMode = PreferencesMode.MODE_PRIVATE;
|
martino2k6/StoreBox
|
storebox-lib/src/main/java/net/orange_box/storebox/StoreBox.java
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/enums/PreferencesMode.java
// public enum PreferencesMode {
//
// /**
// * Default.
// *
// * @see android.content.Context#MODE_PRIVATE
// */
// MODE_PRIVATE(Context.MODE_PRIVATE),
//
// /**
// * @see android.content.Context#MODE_MULTI_PROCESS
// */
// MODE_MULTI_PROCESS(Context.MODE_MULTI_PROCESS),
//
// /**
// * @see android.content.Context#MODE_WORLD_READABLE
// */
// @Deprecated
// MODE_WORLD_READABLE(Context.MODE_WORLD_READABLE),
//
// /**
// * @see android.content.Context#MODE_WORLD_WRITEABLE
// */
// @Deprecated
// MODE_WORLD_WRITEABLE(Context.MODE_WORLD_WRITEABLE);
//
// private final int value;
//
// private PreferencesMode(int value) {
// this.value = value;
// }
//
// public int value() {
// return value;
// }
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/enums/PreferencesType.java
// public enum PreferencesType {
//
// /**
// * Default.
// *
// * @see net.orange_box.storebox.annotations.type.DefaultSharedPreferences
// * @see android.preference.PreferenceManager#getDefaultSharedPreferences(
// * android.content.Context)
// */
// DEFAULT_SHARED,
//
// /**
// * @see net.orange_box.storebox.annotations.type.ActivityPreferences
// * @see android.app.Activity#getPreferences(int)
// */
// ACTIVITY,
//
// /**
// * @see net.orange_box.storebox.annotations.type.FilePreferences
// * @see android.content.Context#getSharedPreferences(String, int)
// */
// FILE
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/enums/SaveMode.java
// public enum SaveMode {
//
// /**
// * Default.
// *
// * @see android.content.SharedPreferences.Editor#apply()
// */
// APPLY,
//
// /**
// * @see android.content.SharedPreferences.Editor#commit()
// */
// COMMIT,
//
// /**
// * {@link android.content.SharedPreferences.Editor#apply()} or
// * {@link android.content.SharedPreferences.Editor#commit()} will have
// * to be called explicitly.
// */
// NOME
// }
|
import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import net.orange_box.storebox.annotations.option.SaveOption;
import net.orange_box.storebox.annotations.type.ActivityPreferences;
import net.orange_box.storebox.annotations.type.DefaultSharedPreferences;
import net.orange_box.storebox.annotations.type.FilePreferences;
import net.orange_box.storebox.enums.PreferencesMode;
import net.orange_box.storebox.enums.PreferencesType;
import net.orange_box.storebox.enums.SaveMode;
import java.lang.reflect.Proxy;
import java.util.Locale;
|
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox;
/**
* Creates a no-thrills instance of the supplied interface, by reading any
* options provided through interface-level annotations.
* <p>
* If you'd like to provide options dynamically at run-time, take a look at
* {@link Builder}.
*/
public final class StoreBox {
/**
* @param context - the context under which the
* {@link android.content.SharedPreferences} should be opened
* @param cls - the interface class which should be instantiated
* @return new instance of class {@code cls} using {@code context}
*/
public static <T> T create(Context context, Class<T> cls) {
return new Builder<>(context, cls).build();
}
private StoreBox() {}
/**
* Can be used to provide a customised instance of the supplied interface,
* by setting custom options through builder methods.
*
* @param <T>
*/
public static final class Builder<T> {
private final Context context;
private final Class<T> cls;
private PreferencesType preferencesType = PreferencesType.DEFAULT_SHARED;
private String preferencesName = "";
private PreferencesMode preferencesMode = PreferencesMode.MODE_PRIVATE;
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/enums/PreferencesMode.java
// public enum PreferencesMode {
//
// /**
// * Default.
// *
// * @see android.content.Context#MODE_PRIVATE
// */
// MODE_PRIVATE(Context.MODE_PRIVATE),
//
// /**
// * @see android.content.Context#MODE_MULTI_PROCESS
// */
// MODE_MULTI_PROCESS(Context.MODE_MULTI_PROCESS),
//
// /**
// * @see android.content.Context#MODE_WORLD_READABLE
// */
// @Deprecated
// MODE_WORLD_READABLE(Context.MODE_WORLD_READABLE),
//
// /**
// * @see android.content.Context#MODE_WORLD_WRITEABLE
// */
// @Deprecated
// MODE_WORLD_WRITEABLE(Context.MODE_WORLD_WRITEABLE);
//
// private final int value;
//
// private PreferencesMode(int value) {
// this.value = value;
// }
//
// public int value() {
// return value;
// }
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/enums/PreferencesType.java
// public enum PreferencesType {
//
// /**
// * Default.
// *
// * @see net.orange_box.storebox.annotations.type.DefaultSharedPreferences
// * @see android.preference.PreferenceManager#getDefaultSharedPreferences(
// * android.content.Context)
// */
// DEFAULT_SHARED,
//
// /**
// * @see net.orange_box.storebox.annotations.type.ActivityPreferences
// * @see android.app.Activity#getPreferences(int)
// */
// ACTIVITY,
//
// /**
// * @see net.orange_box.storebox.annotations.type.FilePreferences
// * @see android.content.Context#getSharedPreferences(String, int)
// */
// FILE
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/enums/SaveMode.java
// public enum SaveMode {
//
// /**
// * Default.
// *
// * @see android.content.SharedPreferences.Editor#apply()
// */
// APPLY,
//
// /**
// * @see android.content.SharedPreferences.Editor#commit()
// */
// COMMIT,
//
// /**
// * {@link android.content.SharedPreferences.Editor#apply()} or
// * {@link android.content.SharedPreferences.Editor#commit()} will have
// * to be called explicitly.
// */
// NOME
// }
// Path: storebox-lib/src/main/java/net/orange_box/storebox/StoreBox.java
import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import net.orange_box.storebox.annotations.option.SaveOption;
import net.orange_box.storebox.annotations.type.ActivityPreferences;
import net.orange_box.storebox.annotations.type.DefaultSharedPreferences;
import net.orange_box.storebox.annotations.type.FilePreferences;
import net.orange_box.storebox.enums.PreferencesMode;
import net.orange_box.storebox.enums.PreferencesType;
import net.orange_box.storebox.enums.SaveMode;
import java.lang.reflect.Proxy;
import java.util.Locale;
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox;
/**
* Creates a no-thrills instance of the supplied interface, by reading any
* options provided through interface-level annotations.
* <p>
* If you'd like to provide options dynamically at run-time, take a look at
* {@link Builder}.
*/
public final class StoreBox {
/**
* @param context - the context under which the
* {@link android.content.SharedPreferences} should be opened
* @param cls - the interface class which should be instantiated
* @return new instance of class {@code cls} using {@code context}
*/
public static <T> T create(Context context, Class<T> cls) {
return new Builder<>(context, cls).build();
}
private StoreBox() {}
/**
* Can be used to provide a customised instance of the supplied interface,
* by setting custom options through builder methods.
*
* @param <T>
*/
public static final class Builder<T> {
private final Context context;
private final Class<T> cls;
private PreferencesType preferencesType = PreferencesType.DEFAULT_SHARED;
private String preferencesName = "";
private PreferencesMode preferencesMode = PreferencesMode.MODE_PRIVATE;
|
private SaveMode saveMode = SaveMode.APPLY;
|
martino2k6/StoreBox
|
storebox-lib/src/main/java/net/orange_box/storebox/adapters/base/BaseStringSetTypeAdapter.java
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreBoxTypeAdapter.java
// public interface StoreBoxTypeAdapter<F, T> {
//
// StoreType getStoreType();
//
// T getDefaultValue();
//
// T adaptForPreferences(F value);
//
// F adaptFromPreferences(T value);
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreType.java
// public enum StoreType {
//
// BOOLEAN,
// FLOAT,
// INTEGER,
// LONG,
// STRING,
// STRING_SET
// }
|
import android.annotation.TargetApi;
import android.os.Build;
import android.support.annotation.Nullable;
import net.orange_box.storebox.adapters.StoreBoxTypeAdapter;
import net.orange_box.storebox.adapters.StoreType;
import java.util.Set;
|
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.adapters.base;
/**
* A {@link StoreBoxTypeAdapter} which should be extended in order to provide
* an adapter implementation for storing {@link T} as a {@link Set} of
* {@link String}s.
*
* @param <T> type which needs to be adapted
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public abstract class BaseStringSetTypeAdapter<T> implements
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreBoxTypeAdapter.java
// public interface StoreBoxTypeAdapter<F, T> {
//
// StoreType getStoreType();
//
// T getDefaultValue();
//
// T adaptForPreferences(F value);
//
// F adaptFromPreferences(T value);
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreType.java
// public enum StoreType {
//
// BOOLEAN,
// FLOAT,
// INTEGER,
// LONG,
// STRING,
// STRING_SET
// }
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/base/BaseStringSetTypeAdapter.java
import android.annotation.TargetApi;
import android.os.Build;
import android.support.annotation.Nullable;
import net.orange_box.storebox.adapters.StoreBoxTypeAdapter;
import net.orange_box.storebox.adapters.StoreType;
import java.util.Set;
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.adapters.base;
/**
* A {@link StoreBoxTypeAdapter} which should be extended in order to provide
* an adapter implementation for storing {@link T} as a {@link Set} of
* {@link String}s.
*
* @param <T> type which needs to be adapted
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public abstract class BaseStringSetTypeAdapter<T> implements
|
StoreBoxTypeAdapter<T, Set<String>> {
|
martino2k6/StoreBox
|
storebox-lib/src/main/java/net/orange_box/storebox/adapters/base/BaseStringSetTypeAdapter.java
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreBoxTypeAdapter.java
// public interface StoreBoxTypeAdapter<F, T> {
//
// StoreType getStoreType();
//
// T getDefaultValue();
//
// T adaptForPreferences(F value);
//
// F adaptFromPreferences(T value);
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreType.java
// public enum StoreType {
//
// BOOLEAN,
// FLOAT,
// INTEGER,
// LONG,
// STRING,
// STRING_SET
// }
|
import android.annotation.TargetApi;
import android.os.Build;
import android.support.annotation.Nullable;
import net.orange_box.storebox.adapters.StoreBoxTypeAdapter;
import net.orange_box.storebox.adapters.StoreType;
import java.util.Set;
|
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.adapters.base;
/**
* A {@link StoreBoxTypeAdapter} which should be extended in order to provide
* an adapter implementation for storing {@link T} as a {@link Set} of
* {@link String}s.
*
* @param <T> type which needs to be adapted
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public abstract class BaseStringSetTypeAdapter<T> implements
StoreBoxTypeAdapter<T, Set<String>> {
@Override
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreBoxTypeAdapter.java
// public interface StoreBoxTypeAdapter<F, T> {
//
// StoreType getStoreType();
//
// T getDefaultValue();
//
// T adaptForPreferences(F value);
//
// F adaptFromPreferences(T value);
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreType.java
// public enum StoreType {
//
// BOOLEAN,
// FLOAT,
// INTEGER,
// LONG,
// STRING,
// STRING_SET
// }
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/base/BaseStringSetTypeAdapter.java
import android.annotation.TargetApi;
import android.os.Build;
import android.support.annotation.Nullable;
import net.orange_box.storebox.adapters.StoreBoxTypeAdapter;
import net.orange_box.storebox.adapters.StoreType;
import java.util.Set;
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.adapters.base;
/**
* A {@link StoreBoxTypeAdapter} which should be extended in order to provide
* an adapter implementation for storing {@link T} as a {@link Set} of
* {@link String}s.
*
* @param <T> type which needs to be adapted
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public abstract class BaseStringSetTypeAdapter<T> implements
StoreBoxTypeAdapter<T, Set<String>> {
@Override
|
public final StoreType getStoreType() {
|
martino2k6/StoreBox
|
storebox-lib/src/main/java/net/orange_box/storebox/adapters/base/BaseStringTypeAdapter.java
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreBoxTypeAdapter.java
// public interface StoreBoxTypeAdapter<F, T> {
//
// StoreType getStoreType();
//
// T getDefaultValue();
//
// T adaptForPreferences(F value);
//
// F adaptFromPreferences(T value);
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreType.java
// public enum StoreType {
//
// BOOLEAN,
// FLOAT,
// INTEGER,
// LONG,
// STRING,
// STRING_SET
// }
|
import android.support.annotation.Nullable;
import net.orange_box.storebox.adapters.StoreBoxTypeAdapter;
import net.orange_box.storebox.adapters.StoreType;
|
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.adapters.base;
/**
* A {@link StoreBoxTypeAdapter} which should be extended in order to provide
* an adapter implementation for storing {@link T} as a {@link String}.
*
* @param <T> type which needs to be adapted
*/
public abstract class BaseStringTypeAdapter<T> implements
StoreBoxTypeAdapter<T, String> {
@Override
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreBoxTypeAdapter.java
// public interface StoreBoxTypeAdapter<F, T> {
//
// StoreType getStoreType();
//
// T getDefaultValue();
//
// T adaptForPreferences(F value);
//
// F adaptFromPreferences(T value);
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreType.java
// public enum StoreType {
//
// BOOLEAN,
// FLOAT,
// INTEGER,
// LONG,
// STRING,
// STRING_SET
// }
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/base/BaseStringTypeAdapter.java
import android.support.annotation.Nullable;
import net.orange_box.storebox.adapters.StoreBoxTypeAdapter;
import net.orange_box.storebox.adapters.StoreType;
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.adapters.base;
/**
* A {@link StoreBoxTypeAdapter} which should be extended in order to provide
* an adapter implementation for storing {@link T} as a {@link String}.
*
* @param <T> type which needs to be adapted
*/
public abstract class BaseStringTypeAdapter<T> implements
StoreBoxTypeAdapter<T, String> {
@Override
|
public final StoreType getStoreType() {
|
martino2k6/StoreBox
|
examples/proguard/src/main/java/net/orange_box/storebox/example/proguard/Preferences.java
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/listeners/OnPreferenceValueChangedListener.java
// public interface OnPreferenceValueChangedListener<T> {
//
// void onChanged(T newValue);
// }
|
import net.orange_box.storebox.annotations.method.ClearMethod;
import net.orange_box.storebox.annotations.method.DefaultValue;
import net.orange_box.storebox.annotations.method.KeyByResource;
import net.orange_box.storebox.annotations.method.KeyByString;
import net.orange_box.storebox.annotations.method.RegisterChangeListenerMethod;
import net.orange_box.storebox.annotations.method.UnregisterChangeListenerMethod;
import net.orange_box.storebox.annotations.type.ActivityPreferences;
import net.orange_box.storebox.listeners.OnPreferenceValueChangedListener;
|
package net.orange_box.storebox.example.proguard;
@ActivityPreferences
interface Preferences {
@KeyByString("int")
@DefaultValue(R.integer.default_int)
int getInt();
@KeyByResource(R.string.key_int)
void setInt(int value);
@RegisterChangeListenerMethod
@KeyByString("int")
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/listeners/OnPreferenceValueChangedListener.java
// public interface OnPreferenceValueChangedListener<T> {
//
// void onChanged(T newValue);
// }
// Path: examples/proguard/src/main/java/net/orange_box/storebox/example/proguard/Preferences.java
import net.orange_box.storebox.annotations.method.ClearMethod;
import net.orange_box.storebox.annotations.method.DefaultValue;
import net.orange_box.storebox.annotations.method.KeyByResource;
import net.orange_box.storebox.annotations.method.KeyByString;
import net.orange_box.storebox.annotations.method.RegisterChangeListenerMethod;
import net.orange_box.storebox.annotations.method.UnregisterChangeListenerMethod;
import net.orange_box.storebox.annotations.type.ActivityPreferences;
import net.orange_box.storebox.listeners.OnPreferenceValueChangedListener;
package net.orange_box.storebox.example.proguard;
@ActivityPreferences
interface Preferences {
@KeyByString("int")
@DefaultValue(R.integer.default_int)
int getInt();
@KeyByResource(R.string.key_int)
void setInt(int value);
@RegisterChangeListenerMethod
@KeyByString("int")
|
void regIntListener(OnPreferenceValueChangedListener<Integer> listener);
|
martino2k6/StoreBox
|
storebox-harness/src/main/java/net/orange_box/storebox/harness/interfaces/changes/ChangeListenersInterface.java
|
// Path: storebox-harness/src/main/java/net/orange_box/storebox/harness/types/CustomClass.java
// public class CustomClass {
//
// private int hashCode;
//
// private final String one;
// private final String two;
//
// public CustomClass() {
// this("", "");
// }
//
// public CustomClass(String one, String two) {
// this.one = one;
// this.two = two;
// }
//
// public String getOne() {
// return one;
// }
//
// public String getTwo() {
// return two;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null || !(o instanceof CustomClass)) {
// return false;
// }
//
// final CustomClass other = (CustomClass) o;
// return (one.equals(other.one) && two.equals(other.two));
// }
//
// @Override
// public int hashCode() {
// if (hashCode == 0) {
// hashCode = Arrays.hashCode(new String[] {one, two});
// }
//
// return hashCode;
// }
// }
//
// Path: storebox-harness/src/main/java/net/orange_box/storebox/harness/types/adapters/CustomClassTypeAdapter.java
// public class CustomClassTypeAdapter extends BaseStringTypeAdapter<CustomClass> {
//
// @Nullable
// @Override
// public String adaptForPreferences(@Nullable CustomClass value) {
// if (value == null) {
// return null;
// }
//
// return value.getOne() + "|" + value.getTwo();
// }
//
// @Nullable
// @Override
// public CustomClass adaptFromPreferences(@Nullable String value) {
// if (value == null) {
// return null;
// }
//
// if (value.length() == 1) {
// return new CustomClass();
// } else {
// final String split[] = value.split("\\|");
//
// return new CustomClass(split[0], split[1]);
// }
// }
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/listeners/OnPreferenceValueChangedListener.java
// public interface OnPreferenceValueChangedListener<T> {
//
// void onChanged(T newValue);
// }
|
import net.orange_box.storebox.annotations.method.KeyByString;
import net.orange_box.storebox.annotations.method.TypeAdapter;
import net.orange_box.storebox.annotations.method.RegisterChangeListenerMethod;
import net.orange_box.storebox.annotations.method.UnregisterChangeListenerMethod;
import net.orange_box.storebox.harness.types.CustomClass;
import net.orange_box.storebox.harness.types.adapters.CustomClassTypeAdapter;
import net.orange_box.storebox.listeners.OnPreferenceValueChangedListener;
|
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.harness.interfaces.changes;
public interface ChangeListenersInterface {
@KeyByString("key_int")
void setInt(int value);
@KeyByString("key_int")
@RegisterChangeListenerMethod
void registerIntChangeListener(
|
// Path: storebox-harness/src/main/java/net/orange_box/storebox/harness/types/CustomClass.java
// public class CustomClass {
//
// private int hashCode;
//
// private final String one;
// private final String two;
//
// public CustomClass() {
// this("", "");
// }
//
// public CustomClass(String one, String two) {
// this.one = one;
// this.two = two;
// }
//
// public String getOne() {
// return one;
// }
//
// public String getTwo() {
// return two;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null || !(o instanceof CustomClass)) {
// return false;
// }
//
// final CustomClass other = (CustomClass) o;
// return (one.equals(other.one) && two.equals(other.two));
// }
//
// @Override
// public int hashCode() {
// if (hashCode == 0) {
// hashCode = Arrays.hashCode(new String[] {one, two});
// }
//
// return hashCode;
// }
// }
//
// Path: storebox-harness/src/main/java/net/orange_box/storebox/harness/types/adapters/CustomClassTypeAdapter.java
// public class CustomClassTypeAdapter extends BaseStringTypeAdapter<CustomClass> {
//
// @Nullable
// @Override
// public String adaptForPreferences(@Nullable CustomClass value) {
// if (value == null) {
// return null;
// }
//
// return value.getOne() + "|" + value.getTwo();
// }
//
// @Nullable
// @Override
// public CustomClass adaptFromPreferences(@Nullable String value) {
// if (value == null) {
// return null;
// }
//
// if (value.length() == 1) {
// return new CustomClass();
// } else {
// final String split[] = value.split("\\|");
//
// return new CustomClass(split[0], split[1]);
// }
// }
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/listeners/OnPreferenceValueChangedListener.java
// public interface OnPreferenceValueChangedListener<T> {
//
// void onChanged(T newValue);
// }
// Path: storebox-harness/src/main/java/net/orange_box/storebox/harness/interfaces/changes/ChangeListenersInterface.java
import net.orange_box.storebox.annotations.method.KeyByString;
import net.orange_box.storebox.annotations.method.TypeAdapter;
import net.orange_box.storebox.annotations.method.RegisterChangeListenerMethod;
import net.orange_box.storebox.annotations.method.UnregisterChangeListenerMethod;
import net.orange_box.storebox.harness.types.CustomClass;
import net.orange_box.storebox.harness.types.adapters.CustomClassTypeAdapter;
import net.orange_box.storebox.listeners.OnPreferenceValueChangedListener;
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.harness.interfaces.changes;
public interface ChangeListenersInterface {
@KeyByString("key_int")
void setInt(int value);
@KeyByString("key_int")
@RegisterChangeListenerMethod
void registerIntChangeListener(
|
OnPreferenceValueChangedListener<Integer> listener);
|
martino2k6/StoreBox
|
storebox-harness/src/main/java/net/orange_box/storebox/harness/interfaces/changes/ChangeListenersInterface.java
|
// Path: storebox-harness/src/main/java/net/orange_box/storebox/harness/types/CustomClass.java
// public class CustomClass {
//
// private int hashCode;
//
// private final String one;
// private final String two;
//
// public CustomClass() {
// this("", "");
// }
//
// public CustomClass(String one, String two) {
// this.one = one;
// this.two = two;
// }
//
// public String getOne() {
// return one;
// }
//
// public String getTwo() {
// return two;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null || !(o instanceof CustomClass)) {
// return false;
// }
//
// final CustomClass other = (CustomClass) o;
// return (one.equals(other.one) && two.equals(other.two));
// }
//
// @Override
// public int hashCode() {
// if (hashCode == 0) {
// hashCode = Arrays.hashCode(new String[] {one, two});
// }
//
// return hashCode;
// }
// }
//
// Path: storebox-harness/src/main/java/net/orange_box/storebox/harness/types/adapters/CustomClassTypeAdapter.java
// public class CustomClassTypeAdapter extends BaseStringTypeAdapter<CustomClass> {
//
// @Nullable
// @Override
// public String adaptForPreferences(@Nullable CustomClass value) {
// if (value == null) {
// return null;
// }
//
// return value.getOne() + "|" + value.getTwo();
// }
//
// @Nullable
// @Override
// public CustomClass adaptFromPreferences(@Nullable String value) {
// if (value == null) {
// return null;
// }
//
// if (value.length() == 1) {
// return new CustomClass();
// } else {
// final String split[] = value.split("\\|");
//
// return new CustomClass(split[0], split[1]);
// }
// }
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/listeners/OnPreferenceValueChangedListener.java
// public interface OnPreferenceValueChangedListener<T> {
//
// void onChanged(T newValue);
// }
|
import net.orange_box.storebox.annotations.method.KeyByString;
import net.orange_box.storebox.annotations.method.TypeAdapter;
import net.orange_box.storebox.annotations.method.RegisterChangeListenerMethod;
import net.orange_box.storebox.annotations.method.UnregisterChangeListenerMethod;
import net.orange_box.storebox.harness.types.CustomClass;
import net.orange_box.storebox.harness.types.adapters.CustomClassTypeAdapter;
import net.orange_box.storebox.listeners.OnPreferenceValueChangedListener;
|
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.harness.interfaces.changes;
public interface ChangeListenersInterface {
@KeyByString("key_int")
void setInt(int value);
@KeyByString("key_int")
@RegisterChangeListenerMethod
void registerIntChangeListener(
OnPreferenceValueChangedListener<Integer> listener);
@KeyByString("key_int")
@RegisterChangeListenerMethod
void registerIntChangeListenerVarArgs(
OnPreferenceValueChangedListener<Integer>... listeners);
@KeyByString("key_int")
@UnregisterChangeListenerMethod
void unregisterIntChangeListener(
OnPreferenceValueChangedListener<Integer> listener);
@KeyByString("key_int")
@UnregisterChangeListenerMethod
void unregisterIntChangeListenerVarArgs(
OnPreferenceValueChangedListener<Integer>... listeners);
@KeyByString("key_custom_class")
|
// Path: storebox-harness/src/main/java/net/orange_box/storebox/harness/types/CustomClass.java
// public class CustomClass {
//
// private int hashCode;
//
// private final String one;
// private final String two;
//
// public CustomClass() {
// this("", "");
// }
//
// public CustomClass(String one, String two) {
// this.one = one;
// this.two = two;
// }
//
// public String getOne() {
// return one;
// }
//
// public String getTwo() {
// return two;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null || !(o instanceof CustomClass)) {
// return false;
// }
//
// final CustomClass other = (CustomClass) o;
// return (one.equals(other.one) && two.equals(other.two));
// }
//
// @Override
// public int hashCode() {
// if (hashCode == 0) {
// hashCode = Arrays.hashCode(new String[] {one, two});
// }
//
// return hashCode;
// }
// }
//
// Path: storebox-harness/src/main/java/net/orange_box/storebox/harness/types/adapters/CustomClassTypeAdapter.java
// public class CustomClassTypeAdapter extends BaseStringTypeAdapter<CustomClass> {
//
// @Nullable
// @Override
// public String adaptForPreferences(@Nullable CustomClass value) {
// if (value == null) {
// return null;
// }
//
// return value.getOne() + "|" + value.getTwo();
// }
//
// @Nullable
// @Override
// public CustomClass adaptFromPreferences(@Nullable String value) {
// if (value == null) {
// return null;
// }
//
// if (value.length() == 1) {
// return new CustomClass();
// } else {
// final String split[] = value.split("\\|");
//
// return new CustomClass(split[0], split[1]);
// }
// }
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/listeners/OnPreferenceValueChangedListener.java
// public interface OnPreferenceValueChangedListener<T> {
//
// void onChanged(T newValue);
// }
// Path: storebox-harness/src/main/java/net/orange_box/storebox/harness/interfaces/changes/ChangeListenersInterface.java
import net.orange_box.storebox.annotations.method.KeyByString;
import net.orange_box.storebox.annotations.method.TypeAdapter;
import net.orange_box.storebox.annotations.method.RegisterChangeListenerMethod;
import net.orange_box.storebox.annotations.method.UnregisterChangeListenerMethod;
import net.orange_box.storebox.harness.types.CustomClass;
import net.orange_box.storebox.harness.types.adapters.CustomClassTypeAdapter;
import net.orange_box.storebox.listeners.OnPreferenceValueChangedListener;
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.harness.interfaces.changes;
public interface ChangeListenersInterface {
@KeyByString("key_int")
void setInt(int value);
@KeyByString("key_int")
@RegisterChangeListenerMethod
void registerIntChangeListener(
OnPreferenceValueChangedListener<Integer> listener);
@KeyByString("key_int")
@RegisterChangeListenerMethod
void registerIntChangeListenerVarArgs(
OnPreferenceValueChangedListener<Integer>... listeners);
@KeyByString("key_int")
@UnregisterChangeListenerMethod
void unregisterIntChangeListener(
OnPreferenceValueChangedListener<Integer> listener);
@KeyByString("key_int")
@UnregisterChangeListenerMethod
void unregisterIntChangeListenerVarArgs(
OnPreferenceValueChangedListener<Integer>... listeners);
@KeyByString("key_custom_class")
|
@TypeAdapter(CustomClassTypeAdapter.class)
|
martino2k6/StoreBox
|
storebox-harness/src/main/java/net/orange_box/storebox/harness/interfaces/changes/ChangeListenersInterface.java
|
// Path: storebox-harness/src/main/java/net/orange_box/storebox/harness/types/CustomClass.java
// public class CustomClass {
//
// private int hashCode;
//
// private final String one;
// private final String two;
//
// public CustomClass() {
// this("", "");
// }
//
// public CustomClass(String one, String two) {
// this.one = one;
// this.two = two;
// }
//
// public String getOne() {
// return one;
// }
//
// public String getTwo() {
// return two;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null || !(o instanceof CustomClass)) {
// return false;
// }
//
// final CustomClass other = (CustomClass) o;
// return (one.equals(other.one) && two.equals(other.two));
// }
//
// @Override
// public int hashCode() {
// if (hashCode == 0) {
// hashCode = Arrays.hashCode(new String[] {one, two});
// }
//
// return hashCode;
// }
// }
//
// Path: storebox-harness/src/main/java/net/orange_box/storebox/harness/types/adapters/CustomClassTypeAdapter.java
// public class CustomClassTypeAdapter extends BaseStringTypeAdapter<CustomClass> {
//
// @Nullable
// @Override
// public String adaptForPreferences(@Nullable CustomClass value) {
// if (value == null) {
// return null;
// }
//
// return value.getOne() + "|" + value.getTwo();
// }
//
// @Nullable
// @Override
// public CustomClass adaptFromPreferences(@Nullable String value) {
// if (value == null) {
// return null;
// }
//
// if (value.length() == 1) {
// return new CustomClass();
// } else {
// final String split[] = value.split("\\|");
//
// return new CustomClass(split[0], split[1]);
// }
// }
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/listeners/OnPreferenceValueChangedListener.java
// public interface OnPreferenceValueChangedListener<T> {
//
// void onChanged(T newValue);
// }
|
import net.orange_box.storebox.annotations.method.KeyByString;
import net.orange_box.storebox.annotations.method.TypeAdapter;
import net.orange_box.storebox.annotations.method.RegisterChangeListenerMethod;
import net.orange_box.storebox.annotations.method.UnregisterChangeListenerMethod;
import net.orange_box.storebox.harness.types.CustomClass;
import net.orange_box.storebox.harness.types.adapters.CustomClassTypeAdapter;
import net.orange_box.storebox.listeners.OnPreferenceValueChangedListener;
|
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.harness.interfaces.changes;
public interface ChangeListenersInterface {
@KeyByString("key_int")
void setInt(int value);
@KeyByString("key_int")
@RegisterChangeListenerMethod
void registerIntChangeListener(
OnPreferenceValueChangedListener<Integer> listener);
@KeyByString("key_int")
@RegisterChangeListenerMethod
void registerIntChangeListenerVarArgs(
OnPreferenceValueChangedListener<Integer>... listeners);
@KeyByString("key_int")
@UnregisterChangeListenerMethod
void unregisterIntChangeListener(
OnPreferenceValueChangedListener<Integer> listener);
@KeyByString("key_int")
@UnregisterChangeListenerMethod
void unregisterIntChangeListenerVarArgs(
OnPreferenceValueChangedListener<Integer>... listeners);
@KeyByString("key_custom_class")
@TypeAdapter(CustomClassTypeAdapter.class)
|
// Path: storebox-harness/src/main/java/net/orange_box/storebox/harness/types/CustomClass.java
// public class CustomClass {
//
// private int hashCode;
//
// private final String one;
// private final String two;
//
// public CustomClass() {
// this("", "");
// }
//
// public CustomClass(String one, String two) {
// this.one = one;
// this.two = two;
// }
//
// public String getOne() {
// return one;
// }
//
// public String getTwo() {
// return two;
// }
//
// @Override
// public boolean equals(Object o) {
// if (o == null || !(o instanceof CustomClass)) {
// return false;
// }
//
// final CustomClass other = (CustomClass) o;
// return (one.equals(other.one) && two.equals(other.two));
// }
//
// @Override
// public int hashCode() {
// if (hashCode == 0) {
// hashCode = Arrays.hashCode(new String[] {one, two});
// }
//
// return hashCode;
// }
// }
//
// Path: storebox-harness/src/main/java/net/orange_box/storebox/harness/types/adapters/CustomClassTypeAdapter.java
// public class CustomClassTypeAdapter extends BaseStringTypeAdapter<CustomClass> {
//
// @Nullable
// @Override
// public String adaptForPreferences(@Nullable CustomClass value) {
// if (value == null) {
// return null;
// }
//
// return value.getOne() + "|" + value.getTwo();
// }
//
// @Nullable
// @Override
// public CustomClass adaptFromPreferences(@Nullable String value) {
// if (value == null) {
// return null;
// }
//
// if (value.length() == 1) {
// return new CustomClass();
// } else {
// final String split[] = value.split("\\|");
//
// return new CustomClass(split[0], split[1]);
// }
// }
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/listeners/OnPreferenceValueChangedListener.java
// public interface OnPreferenceValueChangedListener<T> {
//
// void onChanged(T newValue);
// }
// Path: storebox-harness/src/main/java/net/orange_box/storebox/harness/interfaces/changes/ChangeListenersInterface.java
import net.orange_box.storebox.annotations.method.KeyByString;
import net.orange_box.storebox.annotations.method.TypeAdapter;
import net.orange_box.storebox.annotations.method.RegisterChangeListenerMethod;
import net.orange_box.storebox.annotations.method.UnregisterChangeListenerMethod;
import net.orange_box.storebox.harness.types.CustomClass;
import net.orange_box.storebox.harness.types.adapters.CustomClassTypeAdapter;
import net.orange_box.storebox.listeners.OnPreferenceValueChangedListener;
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.harness.interfaces.changes;
public interface ChangeListenersInterface {
@KeyByString("key_int")
void setInt(int value);
@KeyByString("key_int")
@RegisterChangeListenerMethod
void registerIntChangeListener(
OnPreferenceValueChangedListener<Integer> listener);
@KeyByString("key_int")
@RegisterChangeListenerMethod
void registerIntChangeListenerVarArgs(
OnPreferenceValueChangedListener<Integer>... listeners);
@KeyByString("key_int")
@UnregisterChangeListenerMethod
void unregisterIntChangeListener(
OnPreferenceValueChangedListener<Integer> listener);
@KeyByString("key_int")
@UnregisterChangeListenerMethod
void unregisterIntChangeListenerVarArgs(
OnPreferenceValueChangedListener<Integer>... listeners);
@KeyByString("key_custom_class")
@TypeAdapter(CustomClassTypeAdapter.class)
|
void setCustomClass(CustomClass value);
|
martino2k6/StoreBox
|
storebox-lib/src/main/java/net/orange_box/storebox/utils/PreferenceUtils.java
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreType.java
// public enum StoreType {
//
// BOOLEAN,
// FLOAT,
// INTEGER,
// LONG,
// STRING,
// STRING_SET
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/enums/SaveMode.java
// public enum SaveMode {
//
// /**
// * Default.
// *
// * @see android.content.SharedPreferences.Editor#apply()
// */
// APPLY,
//
// /**
// * @see android.content.SharedPreferences.Editor#commit()
// */
// COMMIT,
//
// /**
// * {@link android.content.SharedPreferences.Editor#apply()} or
// * {@link android.content.SharedPreferences.Editor#commit()} will have
// * to be called explicitly.
// */
// NOME
// }
|
import android.annotation.TargetApi;
import android.content.SharedPreferences;
import android.os.Build;
import net.orange_box.storebox.adapters.StoreType;
import net.orange_box.storebox.enums.SaveMode;
import java.util.Locale;
import java.util.Set;
|
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.utils;
public final class PreferenceUtils {
public static Object getValue(
SharedPreferences prefs,
String key,
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreType.java
// public enum StoreType {
//
// BOOLEAN,
// FLOAT,
// INTEGER,
// LONG,
// STRING,
// STRING_SET
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/enums/SaveMode.java
// public enum SaveMode {
//
// /**
// * Default.
// *
// * @see android.content.SharedPreferences.Editor#apply()
// */
// APPLY,
//
// /**
// * @see android.content.SharedPreferences.Editor#commit()
// */
// COMMIT,
//
// /**
// * {@link android.content.SharedPreferences.Editor#apply()} or
// * {@link android.content.SharedPreferences.Editor#commit()} will have
// * to be called explicitly.
// */
// NOME
// }
// Path: storebox-lib/src/main/java/net/orange_box/storebox/utils/PreferenceUtils.java
import android.annotation.TargetApi;
import android.content.SharedPreferences;
import android.os.Build;
import net.orange_box.storebox.adapters.StoreType;
import net.orange_box.storebox.enums.SaveMode;
import java.util.Locale;
import java.util.Set;
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.utils;
public final class PreferenceUtils {
public static Object getValue(
SharedPreferences prefs,
String key,
|
StoreType type,
|
martino2k6/StoreBox
|
storebox-lib/src/main/java/net/orange_box/storebox/utils/PreferenceUtils.java
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreType.java
// public enum StoreType {
//
// BOOLEAN,
// FLOAT,
// INTEGER,
// LONG,
// STRING,
// STRING_SET
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/enums/SaveMode.java
// public enum SaveMode {
//
// /**
// * Default.
// *
// * @see android.content.SharedPreferences.Editor#apply()
// */
// APPLY,
//
// /**
// * @see android.content.SharedPreferences.Editor#commit()
// */
// COMMIT,
//
// /**
// * {@link android.content.SharedPreferences.Editor#apply()} or
// * {@link android.content.SharedPreferences.Editor#commit()} will have
// * to be called explicitly.
// */
// NOME
// }
|
import android.annotation.TargetApi;
import android.content.SharedPreferences;
import android.os.Build;
import net.orange_box.storebox.adapters.StoreType;
import net.orange_box.storebox.enums.SaveMode;
import java.util.Locale;
import java.util.Set;
|
break;
case INTEGER:
editor.putInt(key, (Integer) value);
break;
case LONG:
editor.putLong(key, (Long) value);
break;
case STRING:
editor.putString(key, (String) value);
break;
case STRING_SET:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
putStringSetApi11(editor, key, (Set<String>) value);
break;
}
default:
throw new UnsupportedOperationException(String.format(
Locale.ENGLISH,
"Saving type %1$s into the preferences is not supported",
type.name()));
}
}
public static void saveChanges(
SharedPreferences.Editor editor,
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreType.java
// public enum StoreType {
//
// BOOLEAN,
// FLOAT,
// INTEGER,
// LONG,
// STRING,
// STRING_SET
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/enums/SaveMode.java
// public enum SaveMode {
//
// /**
// * Default.
// *
// * @see android.content.SharedPreferences.Editor#apply()
// */
// APPLY,
//
// /**
// * @see android.content.SharedPreferences.Editor#commit()
// */
// COMMIT,
//
// /**
// * {@link android.content.SharedPreferences.Editor#apply()} or
// * {@link android.content.SharedPreferences.Editor#commit()} will have
// * to be called explicitly.
// */
// NOME
// }
// Path: storebox-lib/src/main/java/net/orange_box/storebox/utils/PreferenceUtils.java
import android.annotation.TargetApi;
import android.content.SharedPreferences;
import android.os.Build;
import net.orange_box.storebox.adapters.StoreType;
import net.orange_box.storebox.enums.SaveMode;
import java.util.Locale;
import java.util.Set;
break;
case INTEGER:
editor.putInt(key, (Integer) value);
break;
case LONG:
editor.putLong(key, (Long) value);
break;
case STRING:
editor.putString(key, (String) value);
break;
case STRING_SET:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
putStringSetApi11(editor, key, (Set<String>) value);
break;
}
default:
throw new UnsupportedOperationException(String.format(
Locale.ENGLISH,
"Saving type %1$s into the preferences is not supported",
type.name()));
}
}
public static void saveChanges(
SharedPreferences.Editor editor,
|
SaveMode mode) {
|
martino2k6/StoreBox
|
storebox-lib/src/main/java/net/orange_box/storebox/adapters/base/BaseFloatTypeAdapter.java
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreBoxTypeAdapter.java
// public interface StoreBoxTypeAdapter<F, T> {
//
// StoreType getStoreType();
//
// T getDefaultValue();
//
// T adaptForPreferences(F value);
//
// F adaptFromPreferences(T value);
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreType.java
// public enum StoreType {
//
// BOOLEAN,
// FLOAT,
// INTEGER,
// LONG,
// STRING,
// STRING_SET
// }
|
import net.orange_box.storebox.adapters.StoreBoxTypeAdapter;
import net.orange_box.storebox.adapters.StoreType;
|
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.adapters.base;
/**
* A {@link StoreBoxTypeAdapter} which should be extended in order to provide
* an adapter implementation for storing {@link T} as a {@link Float}.
*
* @param <T> type which needs to be adapted
*/
public abstract class BaseFloatTypeAdapter<T> implements
StoreBoxTypeAdapter<T, Float> {
protected float DEFAULT;
@Override
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreBoxTypeAdapter.java
// public interface StoreBoxTypeAdapter<F, T> {
//
// StoreType getStoreType();
//
// T getDefaultValue();
//
// T adaptForPreferences(F value);
//
// F adaptFromPreferences(T value);
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreType.java
// public enum StoreType {
//
// BOOLEAN,
// FLOAT,
// INTEGER,
// LONG,
// STRING,
// STRING_SET
// }
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/base/BaseFloatTypeAdapter.java
import net.orange_box.storebox.adapters.StoreBoxTypeAdapter;
import net.orange_box.storebox.adapters.StoreType;
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.adapters.base;
/**
* A {@link StoreBoxTypeAdapter} which should be extended in order to provide
* an adapter implementation for storing {@link T} as a {@link Float}.
*
* @param <T> type which needs to be adapted
*/
public abstract class BaseFloatTypeAdapter<T> implements
StoreBoxTypeAdapter<T, Float> {
protected float DEFAULT;
@Override
|
public final StoreType getStoreType() {
|
martino2k6/StoreBox
|
storebox-harness/src/androidTest/java/net/orange_box/storebox/harness/base/PreferencesTestCase.java
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/StoreBox.java
// public final class StoreBox {
//
// /**
// * @param context - the context under which the
// * {@link android.content.SharedPreferences} should be opened
// * @param cls - the interface class which should be instantiated
// * @return new instance of class {@code cls} using {@code context}
// */
// public static <T> T create(Context context, Class<T> cls) {
// return new Builder<>(context, cls).build();
// }
//
// private StoreBox() {}
//
// /**
// * Can be used to provide a customised instance of the supplied interface,
// * by setting custom options through builder methods.
// *
// * @param <T>
// */
// public static final class Builder<T> {
//
// private final Context context;
// private final Class<T> cls;
//
// private PreferencesType preferencesType = PreferencesType.DEFAULT_SHARED;
// private String preferencesName = "";
// private PreferencesMode preferencesMode = PreferencesMode.MODE_PRIVATE;
// private SaveMode saveMode = SaveMode.APPLY;
//
// public Builder(Context context, Class<T> cls) {
// this.context = context;
// this.cls = cls;
//
// readAnnotations();
// }
//
// public Builder preferencesType(PreferencesType value) {
// preferencesType = value;
// return this;
// }
//
// public Builder preferencesType(
// PreferencesType value, String name) {
//
// preferencesType = value;
// preferencesName = name;
// return this;
// }
//
// public Builder preferencesMode(PreferencesMode value) {
// preferencesMode = value;
// return this;
// }
//
// public Builder saveMode(SaveMode value) {
// saveMode = value;
// return this;
// }
//
// /**
// * @return new instance of class {@code cls} using {@code context}
// */
// @SuppressWarnings("unchecked")
// public T build() {
// validate();
//
// return (T) Proxy.newProxyInstance(
// cls.getClassLoader(),
// new Class[]{cls},
// new StoreBoxInvocationHandler(
// context,
// preferencesType,
// preferencesName,
// preferencesMode,
// saveMode));
// }
//
// private void readAnnotations() {
// // type/mode option
// if (cls.isAnnotationPresent(DefaultSharedPreferences.class)) {
// preferencesType(PreferencesType.DEFAULT_SHARED);
// } else if (cls.isAnnotationPresent(ActivityPreferences.class)) {
// final ActivityPreferences annotation =
// cls.getAnnotation(ActivityPreferences.class);
//
// preferencesType(PreferencesType.ACTIVITY);
// preferencesMode(annotation.mode());
// } else if (cls.isAnnotationPresent(FilePreferences.class)) {
// final FilePreferences annotation =
// cls.getAnnotation(FilePreferences.class);
//
// preferencesType(PreferencesType.FILE, annotation.value());
// preferencesMode(annotation.mode());
// }
// // save option
// if (cls.isAnnotationPresent(SaveOption.class)) {
// saveMode(cls.getAnnotation(SaveOption.class).value());
// }
// }
//
// private void validate() {
// if (context == null) {
// throw new IllegalArgumentException(
// "Context cannot be null");
// }
// if (cls == null) {
// throw new IllegalArgumentException(
// "Class cannot be null");
// } else if (!cls.isInterface()) {
// throw new IllegalArgumentException(
// "Class needs to be an interface");
// }
//
// if (preferencesType == PreferencesType.ACTIVITY) {
// if (!(context instanceof Activity)) {
// throw new IllegalArgumentException(String.format(
// Locale.ENGLISH,
// "Cannot use %1$s without an Activity context",
// PreferencesType.ACTIVITY.name()));
// }
// } else if (preferencesType == PreferencesType.FILE) {
// if (TextUtils.isEmpty(preferencesName)) {
// throw new IllegalArgumentException(String.format(
// Locale.ENGLISH,
// "Cannot use %1$s with an empty file name",
// PreferencesType.FILE.name()));
// }
// }
// }
// }
// }
|
import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.test.InstrumentationTestCase;
import net.orange_box.storebox.StoreBox;
|
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.harness.base;
public abstract class PreferencesTestCase<T> extends InstrumentationTestCase {
protected T uut;
private SharedPreferences prefs;
protected abstract Class<T> getInterface();
@Override
protected void setUp() throws Exception {
super.setUp();
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/StoreBox.java
// public final class StoreBox {
//
// /**
// * @param context - the context under which the
// * {@link android.content.SharedPreferences} should be opened
// * @param cls - the interface class which should be instantiated
// * @return new instance of class {@code cls} using {@code context}
// */
// public static <T> T create(Context context, Class<T> cls) {
// return new Builder<>(context, cls).build();
// }
//
// private StoreBox() {}
//
// /**
// * Can be used to provide a customised instance of the supplied interface,
// * by setting custom options through builder methods.
// *
// * @param <T>
// */
// public static final class Builder<T> {
//
// private final Context context;
// private final Class<T> cls;
//
// private PreferencesType preferencesType = PreferencesType.DEFAULT_SHARED;
// private String preferencesName = "";
// private PreferencesMode preferencesMode = PreferencesMode.MODE_PRIVATE;
// private SaveMode saveMode = SaveMode.APPLY;
//
// public Builder(Context context, Class<T> cls) {
// this.context = context;
// this.cls = cls;
//
// readAnnotations();
// }
//
// public Builder preferencesType(PreferencesType value) {
// preferencesType = value;
// return this;
// }
//
// public Builder preferencesType(
// PreferencesType value, String name) {
//
// preferencesType = value;
// preferencesName = name;
// return this;
// }
//
// public Builder preferencesMode(PreferencesMode value) {
// preferencesMode = value;
// return this;
// }
//
// public Builder saveMode(SaveMode value) {
// saveMode = value;
// return this;
// }
//
// /**
// * @return new instance of class {@code cls} using {@code context}
// */
// @SuppressWarnings("unchecked")
// public T build() {
// validate();
//
// return (T) Proxy.newProxyInstance(
// cls.getClassLoader(),
// new Class[]{cls},
// new StoreBoxInvocationHandler(
// context,
// preferencesType,
// preferencesName,
// preferencesMode,
// saveMode));
// }
//
// private void readAnnotations() {
// // type/mode option
// if (cls.isAnnotationPresent(DefaultSharedPreferences.class)) {
// preferencesType(PreferencesType.DEFAULT_SHARED);
// } else if (cls.isAnnotationPresent(ActivityPreferences.class)) {
// final ActivityPreferences annotation =
// cls.getAnnotation(ActivityPreferences.class);
//
// preferencesType(PreferencesType.ACTIVITY);
// preferencesMode(annotation.mode());
// } else if (cls.isAnnotationPresent(FilePreferences.class)) {
// final FilePreferences annotation =
// cls.getAnnotation(FilePreferences.class);
//
// preferencesType(PreferencesType.FILE, annotation.value());
// preferencesMode(annotation.mode());
// }
// // save option
// if (cls.isAnnotationPresent(SaveOption.class)) {
// saveMode(cls.getAnnotation(SaveOption.class).value());
// }
// }
//
// private void validate() {
// if (context == null) {
// throw new IllegalArgumentException(
// "Context cannot be null");
// }
// if (cls == null) {
// throw new IllegalArgumentException(
// "Class cannot be null");
// } else if (!cls.isInterface()) {
// throw new IllegalArgumentException(
// "Class needs to be an interface");
// }
//
// if (preferencesType == PreferencesType.ACTIVITY) {
// if (!(context instanceof Activity)) {
// throw new IllegalArgumentException(String.format(
// Locale.ENGLISH,
// "Cannot use %1$s without an Activity context",
// PreferencesType.ACTIVITY.name()));
// }
// } else if (preferencesType == PreferencesType.FILE) {
// if (TextUtils.isEmpty(preferencesName)) {
// throw new IllegalArgumentException(String.format(
// Locale.ENGLISH,
// "Cannot use %1$s with an empty file name",
// PreferencesType.FILE.name()));
// }
// }
// }
// }
// }
// Path: storebox-harness/src/androidTest/java/net/orange_box/storebox/harness/base/PreferencesTestCase.java
import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.test.InstrumentationTestCase;
import net.orange_box.storebox.StoreBox;
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.harness.base;
public abstract class PreferencesTestCase<T> extends InstrumentationTestCase {
protected T uut;
private SharedPreferences prefs;
protected abstract Class<T> getInterface();
@Override
protected void setUp() throws Exception {
super.setUp();
|
uut = StoreBox.create(
|
martino2k6/StoreBox
|
storebox-lib/src/main/java/net/orange_box/storebox/annotations/option/SaveOption.java
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/enums/SaveMode.java
// public enum SaveMode {
//
// /**
// * Default.
// *
// * @see android.content.SharedPreferences.Editor#apply()
// */
// APPLY,
//
// /**
// * @see android.content.SharedPreferences.Editor#commit()
// */
// COMMIT,
//
// /**
// * {@link android.content.SharedPreferences.Editor#apply()} or
// * {@link android.content.SharedPreferences.Editor#commit()} will have
// * to be called explicitly.
// */
// NOME
// }
|
import net.orange_box.storebox.enums.SaveMode;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
|
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.annotations.option;
/**
* Annotation which should be used to define what {@link SaveMode} will be
* applied for get methods which don't specify a default value.
* <p>
* Annotation can be used at interface and method-level, however any
* method-level annotations will take precedence over interface-level
* annotations.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface SaveOption {
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/enums/SaveMode.java
// public enum SaveMode {
//
// /**
// * Default.
// *
// * @see android.content.SharedPreferences.Editor#apply()
// */
// APPLY,
//
// /**
// * @see android.content.SharedPreferences.Editor#commit()
// */
// COMMIT,
//
// /**
// * {@link android.content.SharedPreferences.Editor#apply()} or
// * {@link android.content.SharedPreferences.Editor#commit()} will have
// * to be called explicitly.
// */
// NOME
// }
// Path: storebox-lib/src/main/java/net/orange_box/storebox/annotations/option/SaveOption.java
import net.orange_box.storebox.enums.SaveMode;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.annotations.option;
/**
* Annotation which should be used to define what {@link SaveMode} will be
* applied for get methods which don't specify a default value.
* <p>
* Annotation can be used at interface and method-level, however any
* method-level annotations will take precedence over interface-level
* annotations.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface SaveOption {
|
SaveMode value();
|
martino2k6/StoreBox
|
storebox-harness/src/androidTest/java/net/orange_box/storebox/harness/ForwardingMethodsTestCase.java
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/StoreBox.java
// public final class StoreBox {
//
// /**
// * @param context - the context under which the
// * {@link android.content.SharedPreferences} should be opened
// * @param cls - the interface class which should be instantiated
// * @return new instance of class {@code cls} using {@code context}
// */
// public static <T> T create(Context context, Class<T> cls) {
// return new Builder<>(context, cls).build();
// }
//
// private StoreBox() {}
//
// /**
// * Can be used to provide a customised instance of the supplied interface,
// * by setting custom options through builder methods.
// *
// * @param <T>
// */
// public static final class Builder<T> {
//
// private final Context context;
// private final Class<T> cls;
//
// private PreferencesType preferencesType = PreferencesType.DEFAULT_SHARED;
// private String preferencesName = "";
// private PreferencesMode preferencesMode = PreferencesMode.MODE_PRIVATE;
// private SaveMode saveMode = SaveMode.APPLY;
//
// public Builder(Context context, Class<T> cls) {
// this.context = context;
// this.cls = cls;
//
// readAnnotations();
// }
//
// public Builder preferencesType(PreferencesType value) {
// preferencesType = value;
// return this;
// }
//
// public Builder preferencesType(
// PreferencesType value, String name) {
//
// preferencesType = value;
// preferencesName = name;
// return this;
// }
//
// public Builder preferencesMode(PreferencesMode value) {
// preferencesMode = value;
// return this;
// }
//
// public Builder saveMode(SaveMode value) {
// saveMode = value;
// return this;
// }
//
// /**
// * @return new instance of class {@code cls} using {@code context}
// */
// @SuppressWarnings("unchecked")
// public T build() {
// validate();
//
// return (T) Proxy.newProxyInstance(
// cls.getClassLoader(),
// new Class[]{cls},
// new StoreBoxInvocationHandler(
// context,
// preferencesType,
// preferencesName,
// preferencesMode,
// saveMode));
// }
//
// private void readAnnotations() {
// // type/mode option
// if (cls.isAnnotationPresent(DefaultSharedPreferences.class)) {
// preferencesType(PreferencesType.DEFAULT_SHARED);
// } else if (cls.isAnnotationPresent(ActivityPreferences.class)) {
// final ActivityPreferences annotation =
// cls.getAnnotation(ActivityPreferences.class);
//
// preferencesType(PreferencesType.ACTIVITY);
// preferencesMode(annotation.mode());
// } else if (cls.isAnnotationPresent(FilePreferences.class)) {
// final FilePreferences annotation =
// cls.getAnnotation(FilePreferences.class);
//
// preferencesType(PreferencesType.FILE, annotation.value());
// preferencesMode(annotation.mode());
// }
// // save option
// if (cls.isAnnotationPresent(SaveOption.class)) {
// saveMode(cls.getAnnotation(SaveOption.class).value());
// }
// }
//
// private void validate() {
// if (context == null) {
// throw new IllegalArgumentException(
// "Context cannot be null");
// }
// if (cls == null) {
// throw new IllegalArgumentException(
// "Class cannot be null");
// } else if (!cls.isInterface()) {
// throw new IllegalArgumentException(
// "Class needs to be an interface");
// }
//
// if (preferencesType == PreferencesType.ACTIVITY) {
// if (!(context instanceof Activity)) {
// throw new IllegalArgumentException(String.format(
// Locale.ENGLISH,
// "Cannot use %1$s without an Activity context",
// PreferencesType.ACTIVITY.name()));
// }
// } else if (preferencesType == PreferencesType.FILE) {
// if (TextUtils.isEmpty(preferencesName)) {
// throw new IllegalArgumentException(String.format(
// Locale.ENGLISH,
// "Cannot use %1$s with an empty file name",
// PreferencesType.FILE.name()));
// }
// }
// }
// }
// }
//
// Path: storebox-harness/src/main/java/net/orange_box/storebox/harness/activities/TestActivity.java
// public class TestActivity extends Activity {
//
// // NOP
// }
//
// Path: storebox-harness/src/main/java/net/orange_box/storebox/harness/interfaces/ForwardingMethodsInterface.java
// public interface ForwardingMethodsInterface
// extends SharedPreferences, SharedPreferences.Editor {
// }
|
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.annotation.SuppressLint;
import android.app.Instrumentation;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.SharedPreferences;
import android.test.ActivityUnitTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import net.orange_box.storebox.StoreBox;
import net.orange_box.storebox.harness.activities.TestActivity;
import net.orange_box.storebox.harness.interfaces.ForwardingMethodsInterface;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
|
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.harness;
public class ForwardingMethodsTestCase extends ActivityUnitTestCase<TestActivity> {
private SharedPreferences prefs;
private SharedPreferences.Editor editor;
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/StoreBox.java
// public final class StoreBox {
//
// /**
// * @param context - the context under which the
// * {@link android.content.SharedPreferences} should be opened
// * @param cls - the interface class which should be instantiated
// * @return new instance of class {@code cls} using {@code context}
// */
// public static <T> T create(Context context, Class<T> cls) {
// return new Builder<>(context, cls).build();
// }
//
// private StoreBox() {}
//
// /**
// * Can be used to provide a customised instance of the supplied interface,
// * by setting custom options through builder methods.
// *
// * @param <T>
// */
// public static final class Builder<T> {
//
// private final Context context;
// private final Class<T> cls;
//
// private PreferencesType preferencesType = PreferencesType.DEFAULT_SHARED;
// private String preferencesName = "";
// private PreferencesMode preferencesMode = PreferencesMode.MODE_PRIVATE;
// private SaveMode saveMode = SaveMode.APPLY;
//
// public Builder(Context context, Class<T> cls) {
// this.context = context;
// this.cls = cls;
//
// readAnnotations();
// }
//
// public Builder preferencesType(PreferencesType value) {
// preferencesType = value;
// return this;
// }
//
// public Builder preferencesType(
// PreferencesType value, String name) {
//
// preferencesType = value;
// preferencesName = name;
// return this;
// }
//
// public Builder preferencesMode(PreferencesMode value) {
// preferencesMode = value;
// return this;
// }
//
// public Builder saveMode(SaveMode value) {
// saveMode = value;
// return this;
// }
//
// /**
// * @return new instance of class {@code cls} using {@code context}
// */
// @SuppressWarnings("unchecked")
// public T build() {
// validate();
//
// return (T) Proxy.newProxyInstance(
// cls.getClassLoader(),
// new Class[]{cls},
// new StoreBoxInvocationHandler(
// context,
// preferencesType,
// preferencesName,
// preferencesMode,
// saveMode));
// }
//
// private void readAnnotations() {
// // type/mode option
// if (cls.isAnnotationPresent(DefaultSharedPreferences.class)) {
// preferencesType(PreferencesType.DEFAULT_SHARED);
// } else if (cls.isAnnotationPresent(ActivityPreferences.class)) {
// final ActivityPreferences annotation =
// cls.getAnnotation(ActivityPreferences.class);
//
// preferencesType(PreferencesType.ACTIVITY);
// preferencesMode(annotation.mode());
// } else if (cls.isAnnotationPresent(FilePreferences.class)) {
// final FilePreferences annotation =
// cls.getAnnotation(FilePreferences.class);
//
// preferencesType(PreferencesType.FILE, annotation.value());
// preferencesMode(annotation.mode());
// }
// // save option
// if (cls.isAnnotationPresent(SaveOption.class)) {
// saveMode(cls.getAnnotation(SaveOption.class).value());
// }
// }
//
// private void validate() {
// if (context == null) {
// throw new IllegalArgumentException(
// "Context cannot be null");
// }
// if (cls == null) {
// throw new IllegalArgumentException(
// "Class cannot be null");
// } else if (!cls.isInterface()) {
// throw new IllegalArgumentException(
// "Class needs to be an interface");
// }
//
// if (preferencesType == PreferencesType.ACTIVITY) {
// if (!(context instanceof Activity)) {
// throw new IllegalArgumentException(String.format(
// Locale.ENGLISH,
// "Cannot use %1$s without an Activity context",
// PreferencesType.ACTIVITY.name()));
// }
// } else if (preferencesType == PreferencesType.FILE) {
// if (TextUtils.isEmpty(preferencesName)) {
// throw new IllegalArgumentException(String.format(
// Locale.ENGLISH,
// "Cannot use %1$s with an empty file name",
// PreferencesType.FILE.name()));
// }
// }
// }
// }
// }
//
// Path: storebox-harness/src/main/java/net/orange_box/storebox/harness/activities/TestActivity.java
// public class TestActivity extends Activity {
//
// // NOP
// }
//
// Path: storebox-harness/src/main/java/net/orange_box/storebox/harness/interfaces/ForwardingMethodsInterface.java
// public interface ForwardingMethodsInterface
// extends SharedPreferences, SharedPreferences.Editor {
// }
// Path: storebox-harness/src/androidTest/java/net/orange_box/storebox/harness/ForwardingMethodsTestCase.java
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.annotation.SuppressLint;
import android.app.Instrumentation;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.SharedPreferences;
import android.test.ActivityUnitTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import net.orange_box.storebox.StoreBox;
import net.orange_box.storebox.harness.activities.TestActivity;
import net.orange_box.storebox.harness.interfaces.ForwardingMethodsInterface;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.harness;
public class ForwardingMethodsTestCase extends ActivityUnitTestCase<TestActivity> {
private SharedPreferences prefs;
private SharedPreferences.Editor editor;
|
private ForwardingMethodsInterface uut;
|
martino2k6/StoreBox
|
storebox-lib/src/main/java/net/orange_box/storebox/adapters/base/BaseLongTypeAdapter.java
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreBoxTypeAdapter.java
// public interface StoreBoxTypeAdapter<F, T> {
//
// StoreType getStoreType();
//
// T getDefaultValue();
//
// T adaptForPreferences(F value);
//
// F adaptFromPreferences(T value);
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreType.java
// public enum StoreType {
//
// BOOLEAN,
// FLOAT,
// INTEGER,
// LONG,
// STRING,
// STRING_SET
// }
|
import net.orange_box.storebox.adapters.StoreBoxTypeAdapter;
import net.orange_box.storebox.adapters.StoreType;
|
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.adapters.base;
/**
* A {@link StoreBoxTypeAdapter} which should be extended in order to provide
* an adapter implementation for storing {@link T} as a {@link Long}.
*
* @param <T> type which needs to be adapted
*/
public abstract class BaseLongTypeAdapter<T> implements
StoreBoxTypeAdapter<T, Long> {
protected long DEFAULT;
@Override
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreBoxTypeAdapter.java
// public interface StoreBoxTypeAdapter<F, T> {
//
// StoreType getStoreType();
//
// T getDefaultValue();
//
// T adaptForPreferences(F value);
//
// F adaptFromPreferences(T value);
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreType.java
// public enum StoreType {
//
// BOOLEAN,
// FLOAT,
// INTEGER,
// LONG,
// STRING,
// STRING_SET
// }
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/base/BaseLongTypeAdapter.java
import net.orange_box.storebox.adapters.StoreBoxTypeAdapter;
import net.orange_box.storebox.adapters.StoreType;
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.adapters.base;
/**
* A {@link StoreBoxTypeAdapter} which should be extended in order to provide
* an adapter implementation for storing {@link T} as a {@link Long}.
*
* @param <T> type which needs to be adapted
*/
public abstract class BaseLongTypeAdapter<T> implements
StoreBoxTypeAdapter<T, Long> {
protected long DEFAULT;
@Override
|
public final StoreType getStoreType() {
|
martino2k6/StoreBox
|
storebox-lib/src/main/java/net/orange_box/storebox/annotations/method/TypeAdapter.java
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreBoxTypeAdapter.java
// public interface StoreBoxTypeAdapter<F, T> {
//
// StoreType getStoreType();
//
// T getDefaultValue();
//
// T adaptForPreferences(F value);
//
// F adaptFromPreferences(T value);
// }
|
import net.orange_box.storebox.adapters.StoreBoxTypeAdapter;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
|
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.annotations.method;
/**
* Annotation which should be used on set and get methods to declare the
* {@link StoreBoxTypeAdapter} to be used for adapting the type for the
* preferences.
* <p>
* Type adapters for {@link java.util.Date}, {@link Enum}, and
* {@link android.net.Uri} are already supported and as such there is no need
* to provide a type adapter for them.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface TypeAdapter {
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreBoxTypeAdapter.java
// public interface StoreBoxTypeAdapter<F, T> {
//
// StoreType getStoreType();
//
// T getDefaultValue();
//
// T adaptForPreferences(F value);
//
// F adaptFromPreferences(T value);
// }
// Path: storebox-lib/src/main/java/net/orange_box/storebox/annotations/method/TypeAdapter.java
import net.orange_box.storebox.adapters.StoreBoxTypeAdapter;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.annotations.method;
/**
* Annotation which should be used on set and get methods to declare the
* {@link StoreBoxTypeAdapter} to be used for adapting the type for the
* preferences.
* <p>
* Type adapters for {@link java.util.Date}, {@link Enum}, and
* {@link android.net.Uri} are already supported and as such there is no need
* to provide a type adapter for them.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface TypeAdapter {
|
Class<? extends StoreBoxTypeAdapter> value();
|
martino2k6/StoreBox
|
examples/proguard/src/main/java/net/orange_box/storebox/example/proguard/MainActivity.java
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/StoreBox.java
// public final class StoreBox {
//
// /**
// * @param context - the context under which the
// * {@link android.content.SharedPreferences} should be opened
// * @param cls - the interface class which should be instantiated
// * @return new instance of class {@code cls} using {@code context}
// */
// public static <T> T create(Context context, Class<T> cls) {
// return new Builder<>(context, cls).build();
// }
//
// private StoreBox() {}
//
// /**
// * Can be used to provide a customised instance of the supplied interface,
// * by setting custom options through builder methods.
// *
// * @param <T>
// */
// public static final class Builder<T> {
//
// private final Context context;
// private final Class<T> cls;
//
// private PreferencesType preferencesType = PreferencesType.DEFAULT_SHARED;
// private String preferencesName = "";
// private PreferencesMode preferencesMode = PreferencesMode.MODE_PRIVATE;
// private SaveMode saveMode = SaveMode.APPLY;
//
// public Builder(Context context, Class<T> cls) {
// this.context = context;
// this.cls = cls;
//
// readAnnotations();
// }
//
// public Builder preferencesType(PreferencesType value) {
// preferencesType = value;
// return this;
// }
//
// public Builder preferencesType(
// PreferencesType value, String name) {
//
// preferencesType = value;
// preferencesName = name;
// return this;
// }
//
// public Builder preferencesMode(PreferencesMode value) {
// preferencesMode = value;
// return this;
// }
//
// public Builder saveMode(SaveMode value) {
// saveMode = value;
// return this;
// }
//
// /**
// * @return new instance of class {@code cls} using {@code context}
// */
// @SuppressWarnings("unchecked")
// public T build() {
// validate();
//
// return (T) Proxy.newProxyInstance(
// cls.getClassLoader(),
// new Class[]{cls},
// new StoreBoxInvocationHandler(
// context,
// preferencesType,
// preferencesName,
// preferencesMode,
// saveMode));
// }
//
// private void readAnnotations() {
// // type/mode option
// if (cls.isAnnotationPresent(DefaultSharedPreferences.class)) {
// preferencesType(PreferencesType.DEFAULT_SHARED);
// } else if (cls.isAnnotationPresent(ActivityPreferences.class)) {
// final ActivityPreferences annotation =
// cls.getAnnotation(ActivityPreferences.class);
//
// preferencesType(PreferencesType.ACTIVITY);
// preferencesMode(annotation.mode());
// } else if (cls.isAnnotationPresent(FilePreferences.class)) {
// final FilePreferences annotation =
// cls.getAnnotation(FilePreferences.class);
//
// preferencesType(PreferencesType.FILE, annotation.value());
// preferencesMode(annotation.mode());
// }
// // save option
// if (cls.isAnnotationPresent(SaveOption.class)) {
// saveMode(cls.getAnnotation(SaveOption.class).value());
// }
// }
//
// private void validate() {
// if (context == null) {
// throw new IllegalArgumentException(
// "Context cannot be null");
// }
// if (cls == null) {
// throw new IllegalArgumentException(
// "Class cannot be null");
// } else if (!cls.isInterface()) {
// throw new IllegalArgumentException(
// "Class needs to be an interface");
// }
//
// if (preferencesType == PreferencesType.ACTIVITY) {
// if (!(context instanceof Activity)) {
// throw new IllegalArgumentException(String.format(
// Locale.ENGLISH,
// "Cannot use %1$s without an Activity context",
// PreferencesType.ACTIVITY.name()));
// }
// } else if (preferencesType == PreferencesType.FILE) {
// if (TextUtils.isEmpty(preferencesName)) {
// throw new IllegalArgumentException(String.format(
// Locale.ENGLISH,
// "Cannot use %1$s with an empty file name",
// PreferencesType.FILE.name()));
// }
// }
// }
// }
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/listeners/OnPreferenceValueChangedListener.java
// public interface OnPreferenceValueChangedListener<T> {
//
// void onChanged(T newValue);
// }
|
import android.app.Activity;
import android.os.Bundle;
import net.orange_box.storebox.StoreBox;
import net.orange_box.storebox.listeners.OnPreferenceValueChangedListener;
import java.util.concurrent.atomic.AtomicInteger;
|
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.example.proguard;
public final class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/StoreBox.java
// public final class StoreBox {
//
// /**
// * @param context - the context under which the
// * {@link android.content.SharedPreferences} should be opened
// * @param cls - the interface class which should be instantiated
// * @return new instance of class {@code cls} using {@code context}
// */
// public static <T> T create(Context context, Class<T> cls) {
// return new Builder<>(context, cls).build();
// }
//
// private StoreBox() {}
//
// /**
// * Can be used to provide a customised instance of the supplied interface,
// * by setting custom options through builder methods.
// *
// * @param <T>
// */
// public static final class Builder<T> {
//
// private final Context context;
// private final Class<T> cls;
//
// private PreferencesType preferencesType = PreferencesType.DEFAULT_SHARED;
// private String preferencesName = "";
// private PreferencesMode preferencesMode = PreferencesMode.MODE_PRIVATE;
// private SaveMode saveMode = SaveMode.APPLY;
//
// public Builder(Context context, Class<T> cls) {
// this.context = context;
// this.cls = cls;
//
// readAnnotations();
// }
//
// public Builder preferencesType(PreferencesType value) {
// preferencesType = value;
// return this;
// }
//
// public Builder preferencesType(
// PreferencesType value, String name) {
//
// preferencesType = value;
// preferencesName = name;
// return this;
// }
//
// public Builder preferencesMode(PreferencesMode value) {
// preferencesMode = value;
// return this;
// }
//
// public Builder saveMode(SaveMode value) {
// saveMode = value;
// return this;
// }
//
// /**
// * @return new instance of class {@code cls} using {@code context}
// */
// @SuppressWarnings("unchecked")
// public T build() {
// validate();
//
// return (T) Proxy.newProxyInstance(
// cls.getClassLoader(),
// new Class[]{cls},
// new StoreBoxInvocationHandler(
// context,
// preferencesType,
// preferencesName,
// preferencesMode,
// saveMode));
// }
//
// private void readAnnotations() {
// // type/mode option
// if (cls.isAnnotationPresent(DefaultSharedPreferences.class)) {
// preferencesType(PreferencesType.DEFAULT_SHARED);
// } else if (cls.isAnnotationPresent(ActivityPreferences.class)) {
// final ActivityPreferences annotation =
// cls.getAnnotation(ActivityPreferences.class);
//
// preferencesType(PreferencesType.ACTIVITY);
// preferencesMode(annotation.mode());
// } else if (cls.isAnnotationPresent(FilePreferences.class)) {
// final FilePreferences annotation =
// cls.getAnnotation(FilePreferences.class);
//
// preferencesType(PreferencesType.FILE, annotation.value());
// preferencesMode(annotation.mode());
// }
// // save option
// if (cls.isAnnotationPresent(SaveOption.class)) {
// saveMode(cls.getAnnotation(SaveOption.class).value());
// }
// }
//
// private void validate() {
// if (context == null) {
// throw new IllegalArgumentException(
// "Context cannot be null");
// }
// if (cls == null) {
// throw new IllegalArgumentException(
// "Class cannot be null");
// } else if (!cls.isInterface()) {
// throw new IllegalArgumentException(
// "Class needs to be an interface");
// }
//
// if (preferencesType == PreferencesType.ACTIVITY) {
// if (!(context instanceof Activity)) {
// throw new IllegalArgumentException(String.format(
// Locale.ENGLISH,
// "Cannot use %1$s without an Activity context",
// PreferencesType.ACTIVITY.name()));
// }
// } else if (preferencesType == PreferencesType.FILE) {
// if (TextUtils.isEmpty(preferencesName)) {
// throw new IllegalArgumentException(String.format(
// Locale.ENGLISH,
// "Cannot use %1$s with an empty file name",
// PreferencesType.FILE.name()));
// }
// }
// }
// }
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/listeners/OnPreferenceValueChangedListener.java
// public interface OnPreferenceValueChangedListener<T> {
//
// void onChanged(T newValue);
// }
// Path: examples/proguard/src/main/java/net/orange_box/storebox/example/proguard/MainActivity.java
import android.app.Activity;
import android.os.Bundle;
import net.orange_box.storebox.StoreBox;
import net.orange_box.storebox.listeners.OnPreferenceValueChangedListener;
import java.util.concurrent.atomic.AtomicInteger;
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.example.proguard;
public final class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
|
final Preferences prefs = StoreBox.create(this, Preferences.class);
|
martino2k6/StoreBox
|
examples/proguard/src/main/java/net/orange_box/storebox/example/proguard/MainActivity.java
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/StoreBox.java
// public final class StoreBox {
//
// /**
// * @param context - the context under which the
// * {@link android.content.SharedPreferences} should be opened
// * @param cls - the interface class which should be instantiated
// * @return new instance of class {@code cls} using {@code context}
// */
// public static <T> T create(Context context, Class<T> cls) {
// return new Builder<>(context, cls).build();
// }
//
// private StoreBox() {}
//
// /**
// * Can be used to provide a customised instance of the supplied interface,
// * by setting custom options through builder methods.
// *
// * @param <T>
// */
// public static final class Builder<T> {
//
// private final Context context;
// private final Class<T> cls;
//
// private PreferencesType preferencesType = PreferencesType.DEFAULT_SHARED;
// private String preferencesName = "";
// private PreferencesMode preferencesMode = PreferencesMode.MODE_PRIVATE;
// private SaveMode saveMode = SaveMode.APPLY;
//
// public Builder(Context context, Class<T> cls) {
// this.context = context;
// this.cls = cls;
//
// readAnnotations();
// }
//
// public Builder preferencesType(PreferencesType value) {
// preferencesType = value;
// return this;
// }
//
// public Builder preferencesType(
// PreferencesType value, String name) {
//
// preferencesType = value;
// preferencesName = name;
// return this;
// }
//
// public Builder preferencesMode(PreferencesMode value) {
// preferencesMode = value;
// return this;
// }
//
// public Builder saveMode(SaveMode value) {
// saveMode = value;
// return this;
// }
//
// /**
// * @return new instance of class {@code cls} using {@code context}
// */
// @SuppressWarnings("unchecked")
// public T build() {
// validate();
//
// return (T) Proxy.newProxyInstance(
// cls.getClassLoader(),
// new Class[]{cls},
// new StoreBoxInvocationHandler(
// context,
// preferencesType,
// preferencesName,
// preferencesMode,
// saveMode));
// }
//
// private void readAnnotations() {
// // type/mode option
// if (cls.isAnnotationPresent(DefaultSharedPreferences.class)) {
// preferencesType(PreferencesType.DEFAULT_SHARED);
// } else if (cls.isAnnotationPresent(ActivityPreferences.class)) {
// final ActivityPreferences annotation =
// cls.getAnnotation(ActivityPreferences.class);
//
// preferencesType(PreferencesType.ACTIVITY);
// preferencesMode(annotation.mode());
// } else if (cls.isAnnotationPresent(FilePreferences.class)) {
// final FilePreferences annotation =
// cls.getAnnotation(FilePreferences.class);
//
// preferencesType(PreferencesType.FILE, annotation.value());
// preferencesMode(annotation.mode());
// }
// // save option
// if (cls.isAnnotationPresent(SaveOption.class)) {
// saveMode(cls.getAnnotation(SaveOption.class).value());
// }
// }
//
// private void validate() {
// if (context == null) {
// throw new IllegalArgumentException(
// "Context cannot be null");
// }
// if (cls == null) {
// throw new IllegalArgumentException(
// "Class cannot be null");
// } else if (!cls.isInterface()) {
// throw new IllegalArgumentException(
// "Class needs to be an interface");
// }
//
// if (preferencesType == PreferencesType.ACTIVITY) {
// if (!(context instanceof Activity)) {
// throw new IllegalArgumentException(String.format(
// Locale.ENGLISH,
// "Cannot use %1$s without an Activity context",
// PreferencesType.ACTIVITY.name()));
// }
// } else if (preferencesType == PreferencesType.FILE) {
// if (TextUtils.isEmpty(preferencesName)) {
// throw new IllegalArgumentException(String.format(
// Locale.ENGLISH,
// "Cannot use %1$s with an empty file name",
// PreferencesType.FILE.name()));
// }
// }
// }
// }
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/listeners/OnPreferenceValueChangedListener.java
// public interface OnPreferenceValueChangedListener<T> {
//
// void onChanged(T newValue);
// }
|
import android.app.Activity;
import android.os.Bundle;
import net.orange_box.storebox.StoreBox;
import net.orange_box.storebox.listeners.OnPreferenceValueChangedListener;
import java.util.concurrent.atomic.AtomicInteger;
|
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.example.proguard;
public final class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Preferences prefs = StoreBox.create(this, Preferences.class);
prefs.clear();
final AtomicInteger listenerValue = new AtomicInteger(-1);
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/StoreBox.java
// public final class StoreBox {
//
// /**
// * @param context - the context under which the
// * {@link android.content.SharedPreferences} should be opened
// * @param cls - the interface class which should be instantiated
// * @return new instance of class {@code cls} using {@code context}
// */
// public static <T> T create(Context context, Class<T> cls) {
// return new Builder<>(context, cls).build();
// }
//
// private StoreBox() {}
//
// /**
// * Can be used to provide a customised instance of the supplied interface,
// * by setting custom options through builder methods.
// *
// * @param <T>
// */
// public static final class Builder<T> {
//
// private final Context context;
// private final Class<T> cls;
//
// private PreferencesType preferencesType = PreferencesType.DEFAULT_SHARED;
// private String preferencesName = "";
// private PreferencesMode preferencesMode = PreferencesMode.MODE_PRIVATE;
// private SaveMode saveMode = SaveMode.APPLY;
//
// public Builder(Context context, Class<T> cls) {
// this.context = context;
// this.cls = cls;
//
// readAnnotations();
// }
//
// public Builder preferencesType(PreferencesType value) {
// preferencesType = value;
// return this;
// }
//
// public Builder preferencesType(
// PreferencesType value, String name) {
//
// preferencesType = value;
// preferencesName = name;
// return this;
// }
//
// public Builder preferencesMode(PreferencesMode value) {
// preferencesMode = value;
// return this;
// }
//
// public Builder saveMode(SaveMode value) {
// saveMode = value;
// return this;
// }
//
// /**
// * @return new instance of class {@code cls} using {@code context}
// */
// @SuppressWarnings("unchecked")
// public T build() {
// validate();
//
// return (T) Proxy.newProxyInstance(
// cls.getClassLoader(),
// new Class[]{cls},
// new StoreBoxInvocationHandler(
// context,
// preferencesType,
// preferencesName,
// preferencesMode,
// saveMode));
// }
//
// private void readAnnotations() {
// // type/mode option
// if (cls.isAnnotationPresent(DefaultSharedPreferences.class)) {
// preferencesType(PreferencesType.DEFAULT_SHARED);
// } else if (cls.isAnnotationPresent(ActivityPreferences.class)) {
// final ActivityPreferences annotation =
// cls.getAnnotation(ActivityPreferences.class);
//
// preferencesType(PreferencesType.ACTIVITY);
// preferencesMode(annotation.mode());
// } else if (cls.isAnnotationPresent(FilePreferences.class)) {
// final FilePreferences annotation =
// cls.getAnnotation(FilePreferences.class);
//
// preferencesType(PreferencesType.FILE, annotation.value());
// preferencesMode(annotation.mode());
// }
// // save option
// if (cls.isAnnotationPresent(SaveOption.class)) {
// saveMode(cls.getAnnotation(SaveOption.class).value());
// }
// }
//
// private void validate() {
// if (context == null) {
// throw new IllegalArgumentException(
// "Context cannot be null");
// }
// if (cls == null) {
// throw new IllegalArgumentException(
// "Class cannot be null");
// } else if (!cls.isInterface()) {
// throw new IllegalArgumentException(
// "Class needs to be an interface");
// }
//
// if (preferencesType == PreferencesType.ACTIVITY) {
// if (!(context instanceof Activity)) {
// throw new IllegalArgumentException(String.format(
// Locale.ENGLISH,
// "Cannot use %1$s without an Activity context",
// PreferencesType.ACTIVITY.name()));
// }
// } else if (preferencesType == PreferencesType.FILE) {
// if (TextUtils.isEmpty(preferencesName)) {
// throw new IllegalArgumentException(String.format(
// Locale.ENGLISH,
// "Cannot use %1$s with an empty file name",
// PreferencesType.FILE.name()));
// }
// }
// }
// }
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/listeners/OnPreferenceValueChangedListener.java
// public interface OnPreferenceValueChangedListener<T> {
//
// void onChanged(T newValue);
// }
// Path: examples/proguard/src/main/java/net/orange_box/storebox/example/proguard/MainActivity.java
import android.app.Activity;
import android.os.Bundle;
import net.orange_box.storebox.StoreBox;
import net.orange_box.storebox.listeners.OnPreferenceValueChangedListener;
import java.util.concurrent.atomic.AtomicInteger;
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.example.proguard;
public final class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Preferences prefs = StoreBox.create(this, Preferences.class);
prefs.clear();
final AtomicInteger listenerValue = new AtomicInteger(-1);
|
final OnPreferenceValueChangedListener<Integer> listener =
|
martino2k6/StoreBox
|
storebox-lib/src/main/java/net/orange_box/storebox/annotations/type/ActivityPreferences.java
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/enums/PreferencesMode.java
// public enum PreferencesMode {
//
// /**
// * Default.
// *
// * @see android.content.Context#MODE_PRIVATE
// */
// MODE_PRIVATE(Context.MODE_PRIVATE),
//
// /**
// * @see android.content.Context#MODE_MULTI_PROCESS
// */
// MODE_MULTI_PROCESS(Context.MODE_MULTI_PROCESS),
//
// /**
// * @see android.content.Context#MODE_WORLD_READABLE
// */
// @Deprecated
// MODE_WORLD_READABLE(Context.MODE_WORLD_READABLE),
//
// /**
// * @see android.content.Context#MODE_WORLD_WRITEABLE
// */
// @Deprecated
// MODE_WORLD_WRITEABLE(Context.MODE_WORLD_WRITEABLE);
//
// private final int value;
//
// private PreferencesMode(int value) {
// this.value = value;
// }
//
// public int value() {
// return value;
// }
// }
|
import net.orange_box.storebox.enums.PreferencesMode;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
|
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.annotations.type;
/**
* Annotation which should be used at interface-level to define that the
* preferences private to the Activity should be used.
* <p>
* When this annotation is used an {@link android.app.Activity} context needs
* to be passed in when instantiating the interface using
* {@link net.orange_box.storebox.StoreBox}.
*
* @see net.orange_box.storebox.enums.PreferencesType#ACTIVITY
* @see android.app.Activity#getPreferences(int)
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface ActivityPreferences {
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/enums/PreferencesMode.java
// public enum PreferencesMode {
//
// /**
// * Default.
// *
// * @see android.content.Context#MODE_PRIVATE
// */
// MODE_PRIVATE(Context.MODE_PRIVATE),
//
// /**
// * @see android.content.Context#MODE_MULTI_PROCESS
// */
// MODE_MULTI_PROCESS(Context.MODE_MULTI_PROCESS),
//
// /**
// * @see android.content.Context#MODE_WORLD_READABLE
// */
// @Deprecated
// MODE_WORLD_READABLE(Context.MODE_WORLD_READABLE),
//
// /**
// * @see android.content.Context#MODE_WORLD_WRITEABLE
// */
// @Deprecated
// MODE_WORLD_WRITEABLE(Context.MODE_WORLD_WRITEABLE);
//
// private final int value;
//
// private PreferencesMode(int value) {
// this.value = value;
// }
//
// public int value() {
// return value;
// }
// }
// Path: storebox-lib/src/main/java/net/orange_box/storebox/annotations/type/ActivityPreferences.java
import net.orange_box.storebox.enums.PreferencesMode;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.annotations.type;
/**
* Annotation which should be used at interface-level to define that the
* preferences private to the Activity should be used.
* <p>
* When this annotation is used an {@link android.app.Activity} context needs
* to be passed in when instantiating the interface using
* {@link net.orange_box.storebox.StoreBox}.
*
* @see net.orange_box.storebox.enums.PreferencesType#ACTIVITY
* @see android.app.Activity#getPreferences(int)
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface ActivityPreferences {
|
PreferencesMode mode() default PreferencesMode.MODE_PRIVATE;
|
martino2k6/StoreBox
|
storebox-lib/src/main/java/net/orange_box/storebox/adapters/base/BaseBooleanTypeAdapter.java
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreBoxTypeAdapter.java
// public interface StoreBoxTypeAdapter<F, T> {
//
// StoreType getStoreType();
//
// T getDefaultValue();
//
// T adaptForPreferences(F value);
//
// F adaptFromPreferences(T value);
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreType.java
// public enum StoreType {
//
// BOOLEAN,
// FLOAT,
// INTEGER,
// LONG,
// STRING,
// STRING_SET
// }
|
import net.orange_box.storebox.adapters.StoreBoxTypeAdapter;
import net.orange_box.storebox.adapters.StoreType;
|
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.adapters.base;
/**
* A {@link StoreBoxTypeAdapter} which should be extended in order to provide
* an adapter implementation for storing {@link T} as a {@link Boolean}.
*
* @param <T> type which needs to be adapted
*/
public abstract class BaseBooleanTypeAdapter<T> implements
StoreBoxTypeAdapter<T, Boolean> {
protected boolean DEFAULT;
@Override
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreBoxTypeAdapter.java
// public interface StoreBoxTypeAdapter<F, T> {
//
// StoreType getStoreType();
//
// T getDefaultValue();
//
// T adaptForPreferences(F value);
//
// F adaptFromPreferences(T value);
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreType.java
// public enum StoreType {
//
// BOOLEAN,
// FLOAT,
// INTEGER,
// LONG,
// STRING,
// STRING_SET
// }
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/base/BaseBooleanTypeAdapter.java
import net.orange_box.storebox.adapters.StoreBoxTypeAdapter;
import net.orange_box.storebox.adapters.StoreType;
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.adapters.base;
/**
* A {@link StoreBoxTypeAdapter} which should be extended in order to provide
* an adapter implementation for storing {@link T} as a {@link Boolean}.
*
* @param <T> type which needs to be adapted
*/
public abstract class BaseBooleanTypeAdapter<T> implements
StoreBoxTypeAdapter<T, Boolean> {
protected boolean DEFAULT;
@Override
|
public final StoreType getStoreType() {
|
martino2k6/StoreBox
|
storebox-harness/src/androidTest/java/net/orange_box/storebox/harness/RemoveMethodTestCase.java
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/StoreBox.java
// public final class StoreBox {
//
// /**
// * @param context - the context under which the
// * {@link android.content.SharedPreferences} should be opened
// * @param cls - the interface class which should be instantiated
// * @return new instance of class {@code cls} using {@code context}
// */
// public static <T> T create(Context context, Class<T> cls) {
// return new Builder<>(context, cls).build();
// }
//
// private StoreBox() {}
//
// /**
// * Can be used to provide a customised instance of the supplied interface,
// * by setting custom options through builder methods.
// *
// * @param <T>
// */
// public static final class Builder<T> {
//
// private final Context context;
// private final Class<T> cls;
//
// private PreferencesType preferencesType = PreferencesType.DEFAULT_SHARED;
// private String preferencesName = "";
// private PreferencesMode preferencesMode = PreferencesMode.MODE_PRIVATE;
// private SaveMode saveMode = SaveMode.APPLY;
//
// public Builder(Context context, Class<T> cls) {
// this.context = context;
// this.cls = cls;
//
// readAnnotations();
// }
//
// public Builder preferencesType(PreferencesType value) {
// preferencesType = value;
// return this;
// }
//
// public Builder preferencesType(
// PreferencesType value, String name) {
//
// preferencesType = value;
// preferencesName = name;
// return this;
// }
//
// public Builder preferencesMode(PreferencesMode value) {
// preferencesMode = value;
// return this;
// }
//
// public Builder saveMode(SaveMode value) {
// saveMode = value;
// return this;
// }
//
// /**
// * @return new instance of class {@code cls} using {@code context}
// */
// @SuppressWarnings("unchecked")
// public T build() {
// validate();
//
// return (T) Proxy.newProxyInstance(
// cls.getClassLoader(),
// new Class[]{cls},
// new StoreBoxInvocationHandler(
// context,
// preferencesType,
// preferencesName,
// preferencesMode,
// saveMode));
// }
//
// private void readAnnotations() {
// // type/mode option
// if (cls.isAnnotationPresent(DefaultSharedPreferences.class)) {
// preferencesType(PreferencesType.DEFAULT_SHARED);
// } else if (cls.isAnnotationPresent(ActivityPreferences.class)) {
// final ActivityPreferences annotation =
// cls.getAnnotation(ActivityPreferences.class);
//
// preferencesType(PreferencesType.ACTIVITY);
// preferencesMode(annotation.mode());
// } else if (cls.isAnnotationPresent(FilePreferences.class)) {
// final FilePreferences annotation =
// cls.getAnnotation(FilePreferences.class);
//
// preferencesType(PreferencesType.FILE, annotation.value());
// preferencesMode(annotation.mode());
// }
// // save option
// if (cls.isAnnotationPresent(SaveOption.class)) {
// saveMode(cls.getAnnotation(SaveOption.class).value());
// }
// }
//
// private void validate() {
// if (context == null) {
// throw new IllegalArgumentException(
// "Context cannot be null");
// }
// if (cls == null) {
// throw new IllegalArgumentException(
// "Class cannot be null");
// } else if (!cls.isInterface()) {
// throw new IllegalArgumentException(
// "Class needs to be an interface");
// }
//
// if (preferencesType == PreferencesType.ACTIVITY) {
// if (!(context instanceof Activity)) {
// throw new IllegalArgumentException(String.format(
// Locale.ENGLISH,
// "Cannot use %1$s without an Activity context",
// PreferencesType.ACTIVITY.name()));
// }
// } else if (preferencesType == PreferencesType.FILE) {
// if (TextUtils.isEmpty(preferencesName)) {
// throw new IllegalArgumentException(String.format(
// Locale.ENGLISH,
// "Cannot use %1$s with an empty file name",
// PreferencesType.FILE.name()));
// }
// }
// }
// }
// }
//
// Path: storebox-harness/src/main/java/net/orange_box/storebox/harness/interfaces/RemoveMethodInterface.java
// public interface RemoveMethodInterface {
//
// @RemoveMethod
// void removeUsingStringKey(String key);
//
// @RemoveMethod
// void removeUsingIntKey(int key);
//
// @KeyByString("int")
// @RemoveMethod
// void removeWithStringAnnotation();
//
// @KeyByResource(R.string.key_int)
// @RemoveMethod
// void removeWithResourceAnnotation();
// }
|
import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import net.orange_box.storebox.StoreBox;
import net.orange_box.storebox.harness.interfaces.RemoveMethodInterface;
|
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.harness;
public class RemoveMethodTestCase extends InstrumentationTestCase {
private static final String KEY = "int";
private static final int VALUE = 1;
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/StoreBox.java
// public final class StoreBox {
//
// /**
// * @param context - the context under which the
// * {@link android.content.SharedPreferences} should be opened
// * @param cls - the interface class which should be instantiated
// * @return new instance of class {@code cls} using {@code context}
// */
// public static <T> T create(Context context, Class<T> cls) {
// return new Builder<>(context, cls).build();
// }
//
// private StoreBox() {}
//
// /**
// * Can be used to provide a customised instance of the supplied interface,
// * by setting custom options through builder methods.
// *
// * @param <T>
// */
// public static final class Builder<T> {
//
// private final Context context;
// private final Class<T> cls;
//
// private PreferencesType preferencesType = PreferencesType.DEFAULT_SHARED;
// private String preferencesName = "";
// private PreferencesMode preferencesMode = PreferencesMode.MODE_PRIVATE;
// private SaveMode saveMode = SaveMode.APPLY;
//
// public Builder(Context context, Class<T> cls) {
// this.context = context;
// this.cls = cls;
//
// readAnnotations();
// }
//
// public Builder preferencesType(PreferencesType value) {
// preferencesType = value;
// return this;
// }
//
// public Builder preferencesType(
// PreferencesType value, String name) {
//
// preferencesType = value;
// preferencesName = name;
// return this;
// }
//
// public Builder preferencesMode(PreferencesMode value) {
// preferencesMode = value;
// return this;
// }
//
// public Builder saveMode(SaveMode value) {
// saveMode = value;
// return this;
// }
//
// /**
// * @return new instance of class {@code cls} using {@code context}
// */
// @SuppressWarnings("unchecked")
// public T build() {
// validate();
//
// return (T) Proxy.newProxyInstance(
// cls.getClassLoader(),
// new Class[]{cls},
// new StoreBoxInvocationHandler(
// context,
// preferencesType,
// preferencesName,
// preferencesMode,
// saveMode));
// }
//
// private void readAnnotations() {
// // type/mode option
// if (cls.isAnnotationPresent(DefaultSharedPreferences.class)) {
// preferencesType(PreferencesType.DEFAULT_SHARED);
// } else if (cls.isAnnotationPresent(ActivityPreferences.class)) {
// final ActivityPreferences annotation =
// cls.getAnnotation(ActivityPreferences.class);
//
// preferencesType(PreferencesType.ACTIVITY);
// preferencesMode(annotation.mode());
// } else if (cls.isAnnotationPresent(FilePreferences.class)) {
// final FilePreferences annotation =
// cls.getAnnotation(FilePreferences.class);
//
// preferencesType(PreferencesType.FILE, annotation.value());
// preferencesMode(annotation.mode());
// }
// // save option
// if (cls.isAnnotationPresent(SaveOption.class)) {
// saveMode(cls.getAnnotation(SaveOption.class).value());
// }
// }
//
// private void validate() {
// if (context == null) {
// throw new IllegalArgumentException(
// "Context cannot be null");
// }
// if (cls == null) {
// throw new IllegalArgumentException(
// "Class cannot be null");
// } else if (!cls.isInterface()) {
// throw new IllegalArgumentException(
// "Class needs to be an interface");
// }
//
// if (preferencesType == PreferencesType.ACTIVITY) {
// if (!(context instanceof Activity)) {
// throw new IllegalArgumentException(String.format(
// Locale.ENGLISH,
// "Cannot use %1$s without an Activity context",
// PreferencesType.ACTIVITY.name()));
// }
// } else if (preferencesType == PreferencesType.FILE) {
// if (TextUtils.isEmpty(preferencesName)) {
// throw new IllegalArgumentException(String.format(
// Locale.ENGLISH,
// "Cannot use %1$s with an empty file name",
// PreferencesType.FILE.name()));
// }
// }
// }
// }
// }
//
// Path: storebox-harness/src/main/java/net/orange_box/storebox/harness/interfaces/RemoveMethodInterface.java
// public interface RemoveMethodInterface {
//
// @RemoveMethod
// void removeUsingStringKey(String key);
//
// @RemoveMethod
// void removeUsingIntKey(int key);
//
// @KeyByString("int")
// @RemoveMethod
// void removeWithStringAnnotation();
//
// @KeyByResource(R.string.key_int)
// @RemoveMethod
// void removeWithResourceAnnotation();
// }
// Path: storebox-harness/src/androidTest/java/net/orange_box/storebox/harness/RemoveMethodTestCase.java
import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import net.orange_box.storebox.StoreBox;
import net.orange_box.storebox.harness.interfaces.RemoveMethodInterface;
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.harness;
public class RemoveMethodTestCase extends InstrumentationTestCase {
private static final String KEY = "int";
private static final int VALUE = 1;
|
private RemoveMethodInterface uut;
|
martino2k6/StoreBox
|
storebox-harness/src/androidTest/java/net/orange_box/storebox/harness/RemoveMethodTestCase.java
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/StoreBox.java
// public final class StoreBox {
//
// /**
// * @param context - the context under which the
// * {@link android.content.SharedPreferences} should be opened
// * @param cls - the interface class which should be instantiated
// * @return new instance of class {@code cls} using {@code context}
// */
// public static <T> T create(Context context, Class<T> cls) {
// return new Builder<>(context, cls).build();
// }
//
// private StoreBox() {}
//
// /**
// * Can be used to provide a customised instance of the supplied interface,
// * by setting custom options through builder methods.
// *
// * @param <T>
// */
// public static final class Builder<T> {
//
// private final Context context;
// private final Class<T> cls;
//
// private PreferencesType preferencesType = PreferencesType.DEFAULT_SHARED;
// private String preferencesName = "";
// private PreferencesMode preferencesMode = PreferencesMode.MODE_PRIVATE;
// private SaveMode saveMode = SaveMode.APPLY;
//
// public Builder(Context context, Class<T> cls) {
// this.context = context;
// this.cls = cls;
//
// readAnnotations();
// }
//
// public Builder preferencesType(PreferencesType value) {
// preferencesType = value;
// return this;
// }
//
// public Builder preferencesType(
// PreferencesType value, String name) {
//
// preferencesType = value;
// preferencesName = name;
// return this;
// }
//
// public Builder preferencesMode(PreferencesMode value) {
// preferencesMode = value;
// return this;
// }
//
// public Builder saveMode(SaveMode value) {
// saveMode = value;
// return this;
// }
//
// /**
// * @return new instance of class {@code cls} using {@code context}
// */
// @SuppressWarnings("unchecked")
// public T build() {
// validate();
//
// return (T) Proxy.newProxyInstance(
// cls.getClassLoader(),
// new Class[]{cls},
// new StoreBoxInvocationHandler(
// context,
// preferencesType,
// preferencesName,
// preferencesMode,
// saveMode));
// }
//
// private void readAnnotations() {
// // type/mode option
// if (cls.isAnnotationPresent(DefaultSharedPreferences.class)) {
// preferencesType(PreferencesType.DEFAULT_SHARED);
// } else if (cls.isAnnotationPresent(ActivityPreferences.class)) {
// final ActivityPreferences annotation =
// cls.getAnnotation(ActivityPreferences.class);
//
// preferencesType(PreferencesType.ACTIVITY);
// preferencesMode(annotation.mode());
// } else if (cls.isAnnotationPresent(FilePreferences.class)) {
// final FilePreferences annotation =
// cls.getAnnotation(FilePreferences.class);
//
// preferencesType(PreferencesType.FILE, annotation.value());
// preferencesMode(annotation.mode());
// }
// // save option
// if (cls.isAnnotationPresent(SaveOption.class)) {
// saveMode(cls.getAnnotation(SaveOption.class).value());
// }
// }
//
// private void validate() {
// if (context == null) {
// throw new IllegalArgumentException(
// "Context cannot be null");
// }
// if (cls == null) {
// throw new IllegalArgumentException(
// "Class cannot be null");
// } else if (!cls.isInterface()) {
// throw new IllegalArgumentException(
// "Class needs to be an interface");
// }
//
// if (preferencesType == PreferencesType.ACTIVITY) {
// if (!(context instanceof Activity)) {
// throw new IllegalArgumentException(String.format(
// Locale.ENGLISH,
// "Cannot use %1$s without an Activity context",
// PreferencesType.ACTIVITY.name()));
// }
// } else if (preferencesType == PreferencesType.FILE) {
// if (TextUtils.isEmpty(preferencesName)) {
// throw new IllegalArgumentException(String.format(
// Locale.ENGLISH,
// "Cannot use %1$s with an empty file name",
// PreferencesType.FILE.name()));
// }
// }
// }
// }
// }
//
// Path: storebox-harness/src/main/java/net/orange_box/storebox/harness/interfaces/RemoveMethodInterface.java
// public interface RemoveMethodInterface {
//
// @RemoveMethod
// void removeUsingStringKey(String key);
//
// @RemoveMethod
// void removeUsingIntKey(int key);
//
// @KeyByString("int")
// @RemoveMethod
// void removeWithStringAnnotation();
//
// @KeyByResource(R.string.key_int)
// @RemoveMethod
// void removeWithResourceAnnotation();
// }
|
import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import net.orange_box.storebox.StoreBox;
import net.orange_box.storebox.harness.interfaces.RemoveMethodInterface;
|
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.harness;
public class RemoveMethodTestCase extends InstrumentationTestCase {
private static final String KEY = "int";
private static final int VALUE = 1;
private RemoveMethodInterface uut;
private SharedPreferences prefs;
@SuppressLint("CommitPrefEdits")
@Override
protected void setUp() throws Exception {
super.setUp();
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/StoreBox.java
// public final class StoreBox {
//
// /**
// * @param context - the context under which the
// * {@link android.content.SharedPreferences} should be opened
// * @param cls - the interface class which should be instantiated
// * @return new instance of class {@code cls} using {@code context}
// */
// public static <T> T create(Context context, Class<T> cls) {
// return new Builder<>(context, cls).build();
// }
//
// private StoreBox() {}
//
// /**
// * Can be used to provide a customised instance of the supplied interface,
// * by setting custom options through builder methods.
// *
// * @param <T>
// */
// public static final class Builder<T> {
//
// private final Context context;
// private final Class<T> cls;
//
// private PreferencesType preferencesType = PreferencesType.DEFAULT_SHARED;
// private String preferencesName = "";
// private PreferencesMode preferencesMode = PreferencesMode.MODE_PRIVATE;
// private SaveMode saveMode = SaveMode.APPLY;
//
// public Builder(Context context, Class<T> cls) {
// this.context = context;
// this.cls = cls;
//
// readAnnotations();
// }
//
// public Builder preferencesType(PreferencesType value) {
// preferencesType = value;
// return this;
// }
//
// public Builder preferencesType(
// PreferencesType value, String name) {
//
// preferencesType = value;
// preferencesName = name;
// return this;
// }
//
// public Builder preferencesMode(PreferencesMode value) {
// preferencesMode = value;
// return this;
// }
//
// public Builder saveMode(SaveMode value) {
// saveMode = value;
// return this;
// }
//
// /**
// * @return new instance of class {@code cls} using {@code context}
// */
// @SuppressWarnings("unchecked")
// public T build() {
// validate();
//
// return (T) Proxy.newProxyInstance(
// cls.getClassLoader(),
// new Class[]{cls},
// new StoreBoxInvocationHandler(
// context,
// preferencesType,
// preferencesName,
// preferencesMode,
// saveMode));
// }
//
// private void readAnnotations() {
// // type/mode option
// if (cls.isAnnotationPresent(DefaultSharedPreferences.class)) {
// preferencesType(PreferencesType.DEFAULT_SHARED);
// } else if (cls.isAnnotationPresent(ActivityPreferences.class)) {
// final ActivityPreferences annotation =
// cls.getAnnotation(ActivityPreferences.class);
//
// preferencesType(PreferencesType.ACTIVITY);
// preferencesMode(annotation.mode());
// } else if (cls.isAnnotationPresent(FilePreferences.class)) {
// final FilePreferences annotation =
// cls.getAnnotation(FilePreferences.class);
//
// preferencesType(PreferencesType.FILE, annotation.value());
// preferencesMode(annotation.mode());
// }
// // save option
// if (cls.isAnnotationPresent(SaveOption.class)) {
// saveMode(cls.getAnnotation(SaveOption.class).value());
// }
// }
//
// private void validate() {
// if (context == null) {
// throw new IllegalArgumentException(
// "Context cannot be null");
// }
// if (cls == null) {
// throw new IllegalArgumentException(
// "Class cannot be null");
// } else if (!cls.isInterface()) {
// throw new IllegalArgumentException(
// "Class needs to be an interface");
// }
//
// if (preferencesType == PreferencesType.ACTIVITY) {
// if (!(context instanceof Activity)) {
// throw new IllegalArgumentException(String.format(
// Locale.ENGLISH,
// "Cannot use %1$s without an Activity context",
// PreferencesType.ACTIVITY.name()));
// }
// } else if (preferencesType == PreferencesType.FILE) {
// if (TextUtils.isEmpty(preferencesName)) {
// throw new IllegalArgumentException(String.format(
// Locale.ENGLISH,
// "Cannot use %1$s with an empty file name",
// PreferencesType.FILE.name()));
// }
// }
// }
// }
// }
//
// Path: storebox-harness/src/main/java/net/orange_box/storebox/harness/interfaces/RemoveMethodInterface.java
// public interface RemoveMethodInterface {
//
// @RemoveMethod
// void removeUsingStringKey(String key);
//
// @RemoveMethod
// void removeUsingIntKey(int key);
//
// @KeyByString("int")
// @RemoveMethod
// void removeWithStringAnnotation();
//
// @KeyByResource(R.string.key_int)
// @RemoveMethod
// void removeWithResourceAnnotation();
// }
// Path: storebox-harness/src/androidTest/java/net/orange_box/storebox/harness/RemoveMethodTestCase.java
import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import net.orange_box.storebox.StoreBox;
import net.orange_box.storebox.harness.interfaces.RemoveMethodInterface;
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.harness;
public class RemoveMethodTestCase extends InstrumentationTestCase {
private static final String KEY = "int";
private static final int VALUE = 1;
private RemoveMethodInterface uut;
private SharedPreferences prefs;
@SuppressLint("CommitPrefEdits")
@Override
protected void setUp() throws Exception {
super.setUp();
|
uut = StoreBox.create(
|
martino2k6/StoreBox
|
storebox-lib/src/main/java/net/orange_box/storebox/adapters/base/BaseIntegerTypeAdapter.java
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreBoxTypeAdapter.java
// public interface StoreBoxTypeAdapter<F, T> {
//
// StoreType getStoreType();
//
// T getDefaultValue();
//
// T adaptForPreferences(F value);
//
// F adaptFromPreferences(T value);
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreType.java
// public enum StoreType {
//
// BOOLEAN,
// FLOAT,
// INTEGER,
// LONG,
// STRING,
// STRING_SET
// }
|
import net.orange_box.storebox.adapters.StoreBoxTypeAdapter;
import net.orange_box.storebox.adapters.StoreType;
|
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.adapters.base;
/**
* A {@link StoreBoxTypeAdapter} which should be extended in order to provide
* an adapter implementation for storing {@link T} as an {@link Integer}.
*
* @param <T> type which needs to be adapted
*/
public abstract class BaseIntegerTypeAdapter<T> implements
StoreBoxTypeAdapter<T, Integer> {
protected int DEFAULT;
@Override
|
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreBoxTypeAdapter.java
// public interface StoreBoxTypeAdapter<F, T> {
//
// StoreType getStoreType();
//
// T getDefaultValue();
//
// T adaptForPreferences(F value);
//
// F adaptFromPreferences(T value);
// }
//
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/StoreType.java
// public enum StoreType {
//
// BOOLEAN,
// FLOAT,
// INTEGER,
// LONG,
// STRING,
// STRING_SET
// }
// Path: storebox-lib/src/main/java/net/orange_box/storebox/adapters/base/BaseIntegerTypeAdapter.java
import net.orange_box.storebox.adapters.StoreBoxTypeAdapter;
import net.orange_box.storebox.adapters.StoreType;
/*
* Copyright 2015 Martin Bella
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.orange_box.storebox.adapters.base;
/**
* A {@link StoreBoxTypeAdapter} which should be extended in order to provide
* an adapter implementation for storing {@link T} as an {@link Integer}.
*
* @param <T> type which needs to be adapted
*/
public abstract class BaseIntegerTypeAdapter<T> implements
StoreBoxTypeAdapter<T, Integer> {
protected int DEFAULT;
@Override
|
public final StoreType getStoreType() {
|
bupt1987/JgWeb
|
src/main/java/com/zhaidaosi/game/server/model/zone/DuelZone.java
|
// Path: src/main/java/com/zhaidaosi/game/server/model/player/Player.java
// public class Player extends BasePlayer {
//
// private static Map<Integer, Integer> levelExperience = new HashMap<>();
//
// private UserInfo userInfo;
// private BasePosition oldPosition;
// private Map<String, Integer> actionJson = new HashMap<>();
//
// static {
// levelExperience.put(1, 100);
// levelExperience.put(2, 300);
// levelExperience.put(3, 500);
// }
//
// @SuppressWarnings("unchecked")
// public void init(UserInfo userInfo) {
// this.userInfo = userInfo;
// this.name = userInfo.getNickname();
// this.level = userInfo.getLevel();
// this.totalHp = this.level * 100;
// this.hp = this.totalHp;
// this.experience = userInfo.getExperience();
//
// actionJson = BaseJson.JsonToObject(userInfo.getActions(), Map.class);
//
// for (Map.Entry<String, Integer> entry : actionJson.entrySet()) {
// AttackAction attackAction = (AttackAction) ActionManager.getAction(Integer.parseInt(entry.getKey()));
// attackAction.setLevel(entry.getValue());
// this.addAction(attackAction);
// }
//
// IBaseArea area = AreaManager.getArea(Area.ID);
// area.addPlayer(this);
// }
//
// public UserInfo getUserInfo() {
// return userInfo;
// }
//
// private void upLevel(int level) {
// if (this.level != level) {
// this.level = level;
// userInfo.setLevel(level);
// for (Entry<Integer, IBaseAction> entry : actions.entrySet()) {
// IBaseAction action = entry.getValue();
// if (action instanceof AttackAction) {
// ((AttackAction) action).setLevel(level);
// actionJson.put(Integer.toString(action.getId()), level);
// }
// userInfo.setActions(BaseJson.ObjectToJson(actionJson));
// }
// }
// }
//
// public void addExperience(int experience) {
// this.experience += experience;
// int _level = level;
// Integer _experience = levelExperience.get(_level);
// while (_experience != null && this.experience > _experience) {
// _level++;
// _experience = levelExperience.get(_level);
// }
// userInfo.setExperience(this.experience);
// upLevel(_level);
// RsyncManager.add(id, UserInfoRsync.class, userInfo);
// }
//
// public BasePosition gOldPosition() {
// return oldPosition;
// }
//
// public void sOldPosition(BasePosition oldPosition) {
// this.oldPosition = oldPosition;
// }
//
// }
|
import com.zhaidaosi.game.jgframework.model.area.BaseZone;
import com.zhaidaosi.game.server.model.player.Player;
|
package com.zhaidaosi.game.server.model.zone;
public class DuelZone extends BaseZone {
public final static String ZONE_NAME = "DuelZone";
public DuelZone() {
super(ZONE_NAME);
}
@Override
public void init() {
}
|
// Path: src/main/java/com/zhaidaosi/game/server/model/player/Player.java
// public class Player extends BasePlayer {
//
// private static Map<Integer, Integer> levelExperience = new HashMap<>();
//
// private UserInfo userInfo;
// private BasePosition oldPosition;
// private Map<String, Integer> actionJson = new HashMap<>();
//
// static {
// levelExperience.put(1, 100);
// levelExperience.put(2, 300);
// levelExperience.put(3, 500);
// }
//
// @SuppressWarnings("unchecked")
// public void init(UserInfo userInfo) {
// this.userInfo = userInfo;
// this.name = userInfo.getNickname();
// this.level = userInfo.getLevel();
// this.totalHp = this.level * 100;
// this.hp = this.totalHp;
// this.experience = userInfo.getExperience();
//
// actionJson = BaseJson.JsonToObject(userInfo.getActions(), Map.class);
//
// for (Map.Entry<String, Integer> entry : actionJson.entrySet()) {
// AttackAction attackAction = (AttackAction) ActionManager.getAction(Integer.parseInt(entry.getKey()));
// attackAction.setLevel(entry.getValue());
// this.addAction(attackAction);
// }
//
// IBaseArea area = AreaManager.getArea(Area.ID);
// area.addPlayer(this);
// }
//
// public UserInfo getUserInfo() {
// return userInfo;
// }
//
// private void upLevel(int level) {
// if (this.level != level) {
// this.level = level;
// userInfo.setLevel(level);
// for (Entry<Integer, IBaseAction> entry : actions.entrySet()) {
// IBaseAction action = entry.getValue();
// if (action instanceof AttackAction) {
// ((AttackAction) action).setLevel(level);
// actionJson.put(Integer.toString(action.getId()), level);
// }
// userInfo.setActions(BaseJson.ObjectToJson(actionJson));
// }
// }
// }
//
// public void addExperience(int experience) {
// this.experience += experience;
// int _level = level;
// Integer _experience = levelExperience.get(_level);
// while (_experience != null && this.experience > _experience) {
// _level++;
// _experience = levelExperience.get(_level);
// }
// userInfo.setExperience(this.experience);
// upLevel(_level);
// RsyncManager.add(id, UserInfoRsync.class, userInfo);
// }
//
// public BasePosition gOldPosition() {
// return oldPosition;
// }
//
// public void sOldPosition(BasePosition oldPosition) {
// this.oldPosition = oldPosition;
// }
//
// }
// Path: src/main/java/com/zhaidaosi/game/server/model/zone/DuelZone.java
import com.zhaidaosi.game.jgframework.model.area.BaseZone;
import com.zhaidaosi.game.server.model.player.Player;
package com.zhaidaosi.game.server.model.zone;
public class DuelZone extends BaseZone {
public final static String ZONE_NAME = "DuelZone";
public DuelZone() {
super(ZONE_NAME);
}
@Override
public void init() {
}
|
public void addPlayer(Player player) {
|
bupt1987/JgWeb
|
src/test/java/client/TestSocket.java
|
// Path: src/test/java/model/AuthResult.java
// public class AuthResult {
// public String address;
// public String secret;
//
// public AuthResult(String address, String secret) {
// this.address = address;
// this.secret = secret;
// }
// }
|
import com.zhaidaosi.game.jgframework.common.BaseSocket;
import com.zhaidaosi.game.jgframework.message.InMessage;
import com.zhaidaosi.game.jgframework.session.SessionManager;
import model.AuthResult;
import java.net.URI;
|
package client;
class TestSocket {
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
System.out.println("start time : " + startTime);
for (int i = 1; i <= 100; i++) {
MyThread t = new MyThread("test" + i, "123456");
t.start();
}
}
}
class MyThread extends Thread {
String username;
String password;
public MyThread(String username, String password) {
this.username = username;
this.password = password;
}
public void run() {
try {
long startTime = System.currentTimeMillis();
|
// Path: src/test/java/model/AuthResult.java
// public class AuthResult {
// public String address;
// public String secret;
//
// public AuthResult(String address, String secret) {
// this.address = address;
// this.secret = secret;
// }
// }
// Path: src/test/java/client/TestSocket.java
import com.zhaidaosi.game.jgframework.common.BaseSocket;
import com.zhaidaosi.game.jgframework.message.InMessage;
import com.zhaidaosi.game.jgframework.session.SessionManager;
import model.AuthResult;
import java.net.URI;
package client;
class TestSocket {
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
System.out.println("start time : " + startTime);
for (int i = 1; i <= 100; i++) {
MyThread t = new MyThread("test" + i, "123456");
t.start();
}
}
}
class MyThread extends Thread {
String username;
String password;
public MyThread(String username, String password) {
this.username = username;
this.password = password;
}
public void run() {
try {
long startTime = System.currentTimeMillis();
|
AuthResult ar = TestAuth.auth(username, password);
|
bupt1987/JgWeb
|
src/main/java/com/zhaidaosi/game/server/handler/OnlineUserHandler.java
|
// Path: src/main/java/com/zhaidaosi/game/server/model/area/Area.java
// public class Area extends BaseArea {
//
// public static int ID = 1;
//
// public Area() {
// super(ID, "场景一");
// }
//
// @Override
// public void init() {
//
// }
//
// }
|
import com.zhaidaosi.game.jgframework.handler.BaseHandler;
import com.zhaidaosi.game.jgframework.message.IBaseMessage;
import com.zhaidaosi.game.jgframework.message.InMessage;
import com.zhaidaosi.game.jgframework.message.OutMessage;
import com.zhaidaosi.game.jgframework.model.area.AreaManager;
import com.zhaidaosi.game.server.model.area.Area;
import io.netty.channel.Channel;
|
package com.zhaidaosi.game.server.handler;
public class OnlineUserHandler extends BaseHandler {
@Override
public IBaseMessage run(InMessage im, Channel ch) {
|
// Path: src/main/java/com/zhaidaosi/game/server/model/area/Area.java
// public class Area extends BaseArea {
//
// public static int ID = 1;
//
// public Area() {
// super(ID, "场景一");
// }
//
// @Override
// public void init() {
//
// }
//
// }
// Path: src/main/java/com/zhaidaosi/game/server/handler/OnlineUserHandler.java
import com.zhaidaosi.game.jgframework.handler.BaseHandler;
import com.zhaidaosi.game.jgframework.message.IBaseMessage;
import com.zhaidaosi.game.jgframework.message.InMessage;
import com.zhaidaosi.game.jgframework.message.OutMessage;
import com.zhaidaosi.game.jgframework.model.area.AreaManager;
import com.zhaidaosi.game.server.model.area.Area;
import io.netty.channel.Channel;
package com.zhaidaosi.game.server.handler;
public class OnlineUserHandler extends BaseHandler {
@Override
public IBaseMessage run(InMessage im, Channel ch) {
|
Area area = (Area) AreaManager.getArea(Area.ID);
|
bupt1987/JgWeb
|
src/test/java/client/TestWebSocket.java
|
// Path: src/test/java/model/AuthResult.java
// public class AuthResult {
// public String address;
// public String secret;
//
// public AuthResult(String address, String secret) {
// this.address = address;
// this.secret = secret;
// }
// }
//
// Path: src/test/java/model/MyWebSocketClient.java
// public class MyWebSocketClient extends WebSocketClient {
//
// private boolean received = false;
// private String message;
//
// public MyWebSocketClient(URI serverUri, Draft draft) {
// super(serverUri, draft);
// }
//
// public MyWebSocketClient(URI serverURI) {
// super(serverURI);
// }
//
// public String getMessage() {
// return message;
// }
//
// @Override
// public void send(String text) throws NotYetConnectedException {
// synchronized (this) {
// super.send(text);
// while (!received) {
// try {
// this.wait();
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
// received = false;
// }
// }
//
// @Override
// public void onOpen(ServerHandshake handshakedata) {
// // System.out.println( "opened connection" );
// // if you plan to refuse connection based on ip or httpfields overload: onWebsocketHandshakeReceivedAsClient
// }
//
// @Override
// public void onMessage(String message) {
// this.message = message;
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// public void onFragment(Framedata fragment) {
// System.out.println("received fragment: " + new String(fragment.getPayloadData().array()));
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// @Override
// public void onClose(int code, String reason, boolean remote) {
// // The codecodes are documented in class org.java_websocket.framing.CloseFrame
// // System.out.println( "Connection closed by " + ( remote ? "remote peer" : "us" ) );
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// @Override
// public void onError(Exception ex) {
// ex.printStackTrace();
// // if the error is fatal then onClose will be called additionally
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// }
|
import com.zhaidaosi.game.jgframework.message.InMessage;
import com.zhaidaosi.game.jgframework.session.SessionManager;
import model.AuthResult;
import model.MyWebSocketClient;
import org.java_websocket.drafts.Draft_17;
import java.net.URI;
|
package client;
public class TestWebSocket {
private final URI uri;
private String secret;
TestWebSocket(URI uri, String secret) {
this.uri = uri;
this.secret = secret;
}
void run() throws Exception {
long startTime = System.currentTimeMillis();
|
// Path: src/test/java/model/AuthResult.java
// public class AuthResult {
// public String address;
// public String secret;
//
// public AuthResult(String address, String secret) {
// this.address = address;
// this.secret = secret;
// }
// }
//
// Path: src/test/java/model/MyWebSocketClient.java
// public class MyWebSocketClient extends WebSocketClient {
//
// private boolean received = false;
// private String message;
//
// public MyWebSocketClient(URI serverUri, Draft draft) {
// super(serverUri, draft);
// }
//
// public MyWebSocketClient(URI serverURI) {
// super(serverURI);
// }
//
// public String getMessage() {
// return message;
// }
//
// @Override
// public void send(String text) throws NotYetConnectedException {
// synchronized (this) {
// super.send(text);
// while (!received) {
// try {
// this.wait();
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
// received = false;
// }
// }
//
// @Override
// public void onOpen(ServerHandshake handshakedata) {
// // System.out.println( "opened connection" );
// // if you plan to refuse connection based on ip or httpfields overload: onWebsocketHandshakeReceivedAsClient
// }
//
// @Override
// public void onMessage(String message) {
// this.message = message;
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// public void onFragment(Framedata fragment) {
// System.out.println("received fragment: " + new String(fragment.getPayloadData().array()));
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// @Override
// public void onClose(int code, String reason, boolean remote) {
// // The codecodes are documented in class org.java_websocket.framing.CloseFrame
// // System.out.println( "Connection closed by " + ( remote ? "remote peer" : "us" ) );
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// @Override
// public void onError(Exception ex) {
// ex.printStackTrace();
// // if the error is fatal then onClose will be called additionally
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// }
// Path: src/test/java/client/TestWebSocket.java
import com.zhaidaosi.game.jgframework.message.InMessage;
import com.zhaidaosi.game.jgframework.session.SessionManager;
import model.AuthResult;
import model.MyWebSocketClient;
import org.java_websocket.drafts.Draft_17;
import java.net.URI;
package client;
public class TestWebSocket {
private final URI uri;
private String secret;
TestWebSocket(URI uri, String secret) {
this.uri = uri;
this.secret = secret;
}
void run() throws Exception {
long startTime = System.currentTimeMillis();
|
MyWebSocketClient ch = new MyWebSocketClient(uri, new Draft_17());
|
bupt1987/JgWeb
|
src/test/java/client/TestWebSocket.java
|
// Path: src/test/java/model/AuthResult.java
// public class AuthResult {
// public String address;
// public String secret;
//
// public AuthResult(String address, String secret) {
// this.address = address;
// this.secret = secret;
// }
// }
//
// Path: src/test/java/model/MyWebSocketClient.java
// public class MyWebSocketClient extends WebSocketClient {
//
// private boolean received = false;
// private String message;
//
// public MyWebSocketClient(URI serverUri, Draft draft) {
// super(serverUri, draft);
// }
//
// public MyWebSocketClient(URI serverURI) {
// super(serverURI);
// }
//
// public String getMessage() {
// return message;
// }
//
// @Override
// public void send(String text) throws NotYetConnectedException {
// synchronized (this) {
// super.send(text);
// while (!received) {
// try {
// this.wait();
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
// received = false;
// }
// }
//
// @Override
// public void onOpen(ServerHandshake handshakedata) {
// // System.out.println( "opened connection" );
// // if you plan to refuse connection based on ip or httpfields overload: onWebsocketHandshakeReceivedAsClient
// }
//
// @Override
// public void onMessage(String message) {
// this.message = message;
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// public void onFragment(Framedata fragment) {
// System.out.println("received fragment: " + new String(fragment.getPayloadData().array()));
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// @Override
// public void onClose(int code, String reason, boolean remote) {
// // The codecodes are documented in class org.java_websocket.framing.CloseFrame
// // System.out.println( "Connection closed by " + ( remote ? "remote peer" : "us" ) );
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// @Override
// public void onError(Exception ex) {
// ex.printStackTrace();
// // if the error is fatal then onClose will be called additionally
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// }
|
import com.zhaidaosi.game.jgframework.message.InMessage;
import com.zhaidaosi.game.jgframework.session.SessionManager;
import model.AuthResult;
import model.MyWebSocketClient;
import org.java_websocket.drafts.Draft_17;
import java.net.URI;
|
ch.closeBlocking();
}
long endTime = System.currentTimeMillis();
System.out.println("end time : " + endTime + " | run time :" + (endTime - startTime));
}
public static void main(String[] args) throws Exception {
long startTime = System.currentTimeMillis();
System.out.println(startTime);
for (int i = 10000; i < 11000; i++) {
WebSocketThread t = new WebSocketThread("test" + i, "123456");
t.start();
Thread.sleep(10);
}
}
}
class WebSocketThread extends Thread {
private String username;
private String password;
WebSocketThread(String username, String password) {
this.username = username;
this.password = password;
}
@Override
public void run() {
try {
|
// Path: src/test/java/model/AuthResult.java
// public class AuthResult {
// public String address;
// public String secret;
//
// public AuthResult(String address, String secret) {
// this.address = address;
// this.secret = secret;
// }
// }
//
// Path: src/test/java/model/MyWebSocketClient.java
// public class MyWebSocketClient extends WebSocketClient {
//
// private boolean received = false;
// private String message;
//
// public MyWebSocketClient(URI serverUri, Draft draft) {
// super(serverUri, draft);
// }
//
// public MyWebSocketClient(URI serverURI) {
// super(serverURI);
// }
//
// public String getMessage() {
// return message;
// }
//
// @Override
// public void send(String text) throws NotYetConnectedException {
// synchronized (this) {
// super.send(text);
// while (!received) {
// try {
// this.wait();
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
// received = false;
// }
// }
//
// @Override
// public void onOpen(ServerHandshake handshakedata) {
// // System.out.println( "opened connection" );
// // if you plan to refuse connection based on ip or httpfields overload: onWebsocketHandshakeReceivedAsClient
// }
//
// @Override
// public void onMessage(String message) {
// this.message = message;
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// public void onFragment(Framedata fragment) {
// System.out.println("received fragment: " + new String(fragment.getPayloadData().array()));
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// @Override
// public void onClose(int code, String reason, boolean remote) {
// // The codecodes are documented in class org.java_websocket.framing.CloseFrame
// // System.out.println( "Connection closed by " + ( remote ? "remote peer" : "us" ) );
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// @Override
// public void onError(Exception ex) {
// ex.printStackTrace();
// // if the error is fatal then onClose will be called additionally
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// }
// Path: src/test/java/client/TestWebSocket.java
import com.zhaidaosi.game.jgframework.message.InMessage;
import com.zhaidaosi.game.jgframework.session.SessionManager;
import model.AuthResult;
import model.MyWebSocketClient;
import org.java_websocket.drafts.Draft_17;
import java.net.URI;
ch.closeBlocking();
}
long endTime = System.currentTimeMillis();
System.out.println("end time : " + endTime + " | run time :" + (endTime - startTime));
}
public static void main(String[] args) throws Exception {
long startTime = System.currentTimeMillis();
System.out.println(startTime);
for (int i = 10000; i < 11000; i++) {
WebSocketThread t = new WebSocketThread("test" + i, "123456");
t.start();
Thread.sleep(10);
}
}
}
class WebSocketThread extends Thread {
private String username;
private String password;
WebSocketThread(String username, String password) {
this.username = username;
this.password = password;
}
@Override
public void run() {
try {
|
AuthResult ar = TestAuth.auth(username, password);
|
bupt1987/JgWeb
|
src/main/java/com/zhaidaosi/game/server/rsync/UserRsync.java
|
// Path: src/main/java/com/zhaidaosi/game/server/sdm/model/User.java
// @SuppressWarnings("serial")
// @Entity
// @Table(name = "user", catalog = "jgframework")
// public class User extends BaseModel {
//
// // Fields
//
// private Integer id;
// private String username;
// private String password;
// private Long lastLoginTime;
// private Long creatTime;
//
// // Constructors
//
// /** default constructor */
// public User() {
// }
//
// /** full constructor */
// public User(String username, String password, Long lastLoginTime, Long creatTime) {
// this.username = username;
// this.password = password;
// this.lastLoginTime = lastLoginTime;
// this.creatTime = creatTime;
// }
//
// // Property accessors
// @Id
// @GeneratedValue(strategy = IDENTITY)
// @Column(name = "id", unique = true, nullable = false)
// public Integer getId() {
// return this.id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// @Column(name = "username", nullable = false, length = 30)
// public String getUsername() {
// return this.username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// @Column(name = "password", nullable = false, length = 50)
// public String getPassword() {
// return this.password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// @Column(name = "last_login_time", nullable = false)
// public Long getLastLoginTime() {
// return this.lastLoginTime;
// }
//
// public void setLastLoginTime(Long lastLoginTime) {
// this.lastLoginTime = lastLoginTime;
// }
//
// @Column(name = "creat_time", nullable = false)
// public Long getCreatTime() {
// return this.creatTime;
// }
//
// public void setCreatTime(Long creatTime) {
// this.creatTime = creatTime;
// }
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/sdm/service/UserService.java
// public class UserService extends BaseService {
//
// public final static String BEAN_ID = "userService";
//
// private static BaseLocalCached cached = new BaseLocalCached();
//
// @Autowired
// protected UserDAO dao;
//
// @Autowired
// protected UserInfoDAO userInfoDao;
//
// @PostConstruct
// protected void setDao() {
// super.setDao(dao);
// }
//
// public User findByUserName(String username) {
// String cacheKey = "findByUserName_" + username;
// Object user = cached.get(cacheKey);
// if (cached.checkInvalid(user)) {
// List<?> list = super.findByProperty(UserDAO.USERNAME, username);
// if (list.size() > 0) {
// user = list.get(0);
// } else {
// user = null;
// }
// cached.set("UserService_findByUserName_" + username, list, 300);
// }
// return user == null ? null : (User) user;
// }
//
// public void addUser(String username, String password, String nickName) {
// User user = new User();
// user.setUsername(username);
// user.setPassword(BaseMd5.encrypt(username + password));
// user.setCreatTime(System.currentTimeMillis());
// user.setLastLoginTime(0L);
// dao.save(user);
//
// UserInfo userinfo = new UserInfo();
// userinfo.setActions(UserInfoService.getDefaultActions());
// userinfo.setExperience(0);
// userinfo.setLevel(1);
// userinfo.setNickname(nickName);
// userinfo.setUid(user.getId());
// userInfoDao.save(userinfo);
// }
//
//
// }
|
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.zhaidaosi.game.jgframework.common.sdm.IBaseModel;
import com.zhaidaosi.game.jgframework.common.spring.ServiceManager;
import com.zhaidaosi.game.jgframework.rsync.BaseRsync;
import com.zhaidaosi.game.server.sdm.model.User;
import com.zhaidaosi.game.server.sdm.service.UserService;
|
package com.zhaidaosi.game.server.rsync;
public class UserRsync extends BaseRsync {
private static final Logger log = LoggerFactory.getLogger(UserRsync.class);
@Override
public void runRsync() {
|
// Path: src/main/java/com/zhaidaosi/game/server/sdm/model/User.java
// @SuppressWarnings("serial")
// @Entity
// @Table(name = "user", catalog = "jgframework")
// public class User extends BaseModel {
//
// // Fields
//
// private Integer id;
// private String username;
// private String password;
// private Long lastLoginTime;
// private Long creatTime;
//
// // Constructors
//
// /** default constructor */
// public User() {
// }
//
// /** full constructor */
// public User(String username, String password, Long lastLoginTime, Long creatTime) {
// this.username = username;
// this.password = password;
// this.lastLoginTime = lastLoginTime;
// this.creatTime = creatTime;
// }
//
// // Property accessors
// @Id
// @GeneratedValue(strategy = IDENTITY)
// @Column(name = "id", unique = true, nullable = false)
// public Integer getId() {
// return this.id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// @Column(name = "username", nullable = false, length = 30)
// public String getUsername() {
// return this.username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// @Column(name = "password", nullable = false, length = 50)
// public String getPassword() {
// return this.password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// @Column(name = "last_login_time", nullable = false)
// public Long getLastLoginTime() {
// return this.lastLoginTime;
// }
//
// public void setLastLoginTime(Long lastLoginTime) {
// this.lastLoginTime = lastLoginTime;
// }
//
// @Column(name = "creat_time", nullable = false)
// public Long getCreatTime() {
// return this.creatTime;
// }
//
// public void setCreatTime(Long creatTime) {
// this.creatTime = creatTime;
// }
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/sdm/service/UserService.java
// public class UserService extends BaseService {
//
// public final static String BEAN_ID = "userService";
//
// private static BaseLocalCached cached = new BaseLocalCached();
//
// @Autowired
// protected UserDAO dao;
//
// @Autowired
// protected UserInfoDAO userInfoDao;
//
// @PostConstruct
// protected void setDao() {
// super.setDao(dao);
// }
//
// public User findByUserName(String username) {
// String cacheKey = "findByUserName_" + username;
// Object user = cached.get(cacheKey);
// if (cached.checkInvalid(user)) {
// List<?> list = super.findByProperty(UserDAO.USERNAME, username);
// if (list.size() > 0) {
// user = list.get(0);
// } else {
// user = null;
// }
// cached.set("UserService_findByUserName_" + username, list, 300);
// }
// return user == null ? null : (User) user;
// }
//
// public void addUser(String username, String password, String nickName) {
// User user = new User();
// user.setUsername(username);
// user.setPassword(BaseMd5.encrypt(username + password));
// user.setCreatTime(System.currentTimeMillis());
// user.setLastLoginTime(0L);
// dao.save(user);
//
// UserInfo userinfo = new UserInfo();
// userinfo.setActions(UserInfoService.getDefaultActions());
// userinfo.setExperience(0);
// userinfo.setLevel(1);
// userinfo.setNickname(nickName);
// userinfo.setUid(user.getId());
// userInfoDao.save(userinfo);
// }
//
//
// }
// Path: src/main/java/com/zhaidaosi/game/server/rsync/UserRsync.java
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.zhaidaosi.game.jgframework.common.sdm.IBaseModel;
import com.zhaidaosi.game.jgframework.common.spring.ServiceManager;
import com.zhaidaosi.game.jgframework.rsync.BaseRsync;
import com.zhaidaosi.game.server.sdm.model.User;
import com.zhaidaosi.game.server.sdm.service.UserService;
package com.zhaidaosi.game.server.rsync;
public class UserRsync extends BaseRsync {
private static final Logger log = LoggerFactory.getLogger(UserRsync.class);
@Override
public void runRsync() {
|
UserService service = (UserService) ServiceManager.getService(UserService.BEAN_ID);
|
bupt1987/JgWeb
|
src/main/java/com/zhaidaosi/game/server/rsync/UserRsync.java
|
// Path: src/main/java/com/zhaidaosi/game/server/sdm/model/User.java
// @SuppressWarnings("serial")
// @Entity
// @Table(name = "user", catalog = "jgframework")
// public class User extends BaseModel {
//
// // Fields
//
// private Integer id;
// private String username;
// private String password;
// private Long lastLoginTime;
// private Long creatTime;
//
// // Constructors
//
// /** default constructor */
// public User() {
// }
//
// /** full constructor */
// public User(String username, String password, Long lastLoginTime, Long creatTime) {
// this.username = username;
// this.password = password;
// this.lastLoginTime = lastLoginTime;
// this.creatTime = creatTime;
// }
//
// // Property accessors
// @Id
// @GeneratedValue(strategy = IDENTITY)
// @Column(name = "id", unique = true, nullable = false)
// public Integer getId() {
// return this.id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// @Column(name = "username", nullable = false, length = 30)
// public String getUsername() {
// return this.username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// @Column(name = "password", nullable = false, length = 50)
// public String getPassword() {
// return this.password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// @Column(name = "last_login_time", nullable = false)
// public Long getLastLoginTime() {
// return this.lastLoginTime;
// }
//
// public void setLastLoginTime(Long lastLoginTime) {
// this.lastLoginTime = lastLoginTime;
// }
//
// @Column(name = "creat_time", nullable = false)
// public Long getCreatTime() {
// return this.creatTime;
// }
//
// public void setCreatTime(Long creatTime) {
// this.creatTime = creatTime;
// }
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/sdm/service/UserService.java
// public class UserService extends BaseService {
//
// public final static String BEAN_ID = "userService";
//
// private static BaseLocalCached cached = new BaseLocalCached();
//
// @Autowired
// protected UserDAO dao;
//
// @Autowired
// protected UserInfoDAO userInfoDao;
//
// @PostConstruct
// protected void setDao() {
// super.setDao(dao);
// }
//
// public User findByUserName(String username) {
// String cacheKey = "findByUserName_" + username;
// Object user = cached.get(cacheKey);
// if (cached.checkInvalid(user)) {
// List<?> list = super.findByProperty(UserDAO.USERNAME, username);
// if (list.size() > 0) {
// user = list.get(0);
// } else {
// user = null;
// }
// cached.set("UserService_findByUserName_" + username, list, 300);
// }
// return user == null ? null : (User) user;
// }
//
// public void addUser(String username, String password, String nickName) {
// User user = new User();
// user.setUsername(username);
// user.setPassword(BaseMd5.encrypt(username + password));
// user.setCreatTime(System.currentTimeMillis());
// user.setLastLoginTime(0L);
// dao.save(user);
//
// UserInfo userinfo = new UserInfo();
// userinfo.setActions(UserInfoService.getDefaultActions());
// userinfo.setExperience(0);
// userinfo.setLevel(1);
// userinfo.setNickname(nickName);
// userinfo.setUid(user.getId());
// userInfoDao.save(userinfo);
// }
//
//
// }
|
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.zhaidaosi.game.jgframework.common.sdm.IBaseModel;
import com.zhaidaosi.game.jgframework.common.spring.ServiceManager;
import com.zhaidaosi.game.jgframework.rsync.BaseRsync;
import com.zhaidaosi.game.server.sdm.model.User;
import com.zhaidaosi.game.server.sdm.service.UserService;
|
package com.zhaidaosi.game.server.rsync;
public class UserRsync extends BaseRsync {
private static final Logger log = LoggerFactory.getLogger(UserRsync.class);
@Override
public void runRsync() {
UserService service = (UserService) ServiceManager.getService(UserService.BEAN_ID);
for (Map.Entry<Integer, IBaseModel> entry : rsyncMap.entrySet()) {
|
// Path: src/main/java/com/zhaidaosi/game/server/sdm/model/User.java
// @SuppressWarnings("serial")
// @Entity
// @Table(name = "user", catalog = "jgframework")
// public class User extends BaseModel {
//
// // Fields
//
// private Integer id;
// private String username;
// private String password;
// private Long lastLoginTime;
// private Long creatTime;
//
// // Constructors
//
// /** default constructor */
// public User() {
// }
//
// /** full constructor */
// public User(String username, String password, Long lastLoginTime, Long creatTime) {
// this.username = username;
// this.password = password;
// this.lastLoginTime = lastLoginTime;
// this.creatTime = creatTime;
// }
//
// // Property accessors
// @Id
// @GeneratedValue(strategy = IDENTITY)
// @Column(name = "id", unique = true, nullable = false)
// public Integer getId() {
// return this.id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// @Column(name = "username", nullable = false, length = 30)
// public String getUsername() {
// return this.username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// @Column(name = "password", nullable = false, length = 50)
// public String getPassword() {
// return this.password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// @Column(name = "last_login_time", nullable = false)
// public Long getLastLoginTime() {
// return this.lastLoginTime;
// }
//
// public void setLastLoginTime(Long lastLoginTime) {
// this.lastLoginTime = lastLoginTime;
// }
//
// @Column(name = "creat_time", nullable = false)
// public Long getCreatTime() {
// return this.creatTime;
// }
//
// public void setCreatTime(Long creatTime) {
// this.creatTime = creatTime;
// }
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/sdm/service/UserService.java
// public class UserService extends BaseService {
//
// public final static String BEAN_ID = "userService";
//
// private static BaseLocalCached cached = new BaseLocalCached();
//
// @Autowired
// protected UserDAO dao;
//
// @Autowired
// protected UserInfoDAO userInfoDao;
//
// @PostConstruct
// protected void setDao() {
// super.setDao(dao);
// }
//
// public User findByUserName(String username) {
// String cacheKey = "findByUserName_" + username;
// Object user = cached.get(cacheKey);
// if (cached.checkInvalid(user)) {
// List<?> list = super.findByProperty(UserDAO.USERNAME, username);
// if (list.size() > 0) {
// user = list.get(0);
// } else {
// user = null;
// }
// cached.set("UserService_findByUserName_" + username, list, 300);
// }
// return user == null ? null : (User) user;
// }
//
// public void addUser(String username, String password, String nickName) {
// User user = new User();
// user.setUsername(username);
// user.setPassword(BaseMd5.encrypt(username + password));
// user.setCreatTime(System.currentTimeMillis());
// user.setLastLoginTime(0L);
// dao.save(user);
//
// UserInfo userinfo = new UserInfo();
// userinfo.setActions(UserInfoService.getDefaultActions());
// userinfo.setExperience(0);
// userinfo.setLevel(1);
// userinfo.setNickname(nickName);
// userinfo.setUid(user.getId());
// userInfoDao.save(userinfo);
// }
//
//
// }
// Path: src/main/java/com/zhaidaosi/game/server/rsync/UserRsync.java
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.zhaidaosi.game.jgframework.common.sdm.IBaseModel;
import com.zhaidaosi.game.jgframework.common.spring.ServiceManager;
import com.zhaidaosi.game.jgframework.rsync.BaseRsync;
import com.zhaidaosi.game.server.sdm.model.User;
import com.zhaidaosi.game.server.sdm.service.UserService;
package com.zhaidaosi.game.server.rsync;
public class UserRsync extends BaseRsync {
private static final Logger log = LoggerFactory.getLogger(UserRsync.class);
@Override
public void runRsync() {
UserService service = (UserService) ServiceManager.getService(UserService.BEAN_ID);
for (Map.Entry<Integer, IBaseModel> entry : rsyncMap.entrySet()) {
|
User user = (User) entry.getValue();
|
bupt1987/JgWeb
|
src/main/java/com/zhaidaosi/game/server/model/Duel.java
|
// Path: src/main/java/com/zhaidaosi/game/server/model/player/Player.java
// public class Player extends BasePlayer {
//
// private static Map<Integer, Integer> levelExperience = new HashMap<>();
//
// private UserInfo userInfo;
// private BasePosition oldPosition;
// private Map<String, Integer> actionJson = new HashMap<>();
//
// static {
// levelExperience.put(1, 100);
// levelExperience.put(2, 300);
// levelExperience.put(3, 500);
// }
//
// @SuppressWarnings("unchecked")
// public void init(UserInfo userInfo) {
// this.userInfo = userInfo;
// this.name = userInfo.getNickname();
// this.level = userInfo.getLevel();
// this.totalHp = this.level * 100;
// this.hp = this.totalHp;
// this.experience = userInfo.getExperience();
//
// actionJson = BaseJson.JsonToObject(userInfo.getActions(), Map.class);
//
// for (Map.Entry<String, Integer> entry : actionJson.entrySet()) {
// AttackAction attackAction = (AttackAction) ActionManager.getAction(Integer.parseInt(entry.getKey()));
// attackAction.setLevel(entry.getValue());
// this.addAction(attackAction);
// }
//
// IBaseArea area = AreaManager.getArea(Area.ID);
// area.addPlayer(this);
// }
//
// public UserInfo getUserInfo() {
// return userInfo;
// }
//
// private void upLevel(int level) {
// if (this.level != level) {
// this.level = level;
// userInfo.setLevel(level);
// for (Entry<Integer, IBaseAction> entry : actions.entrySet()) {
// IBaseAction action = entry.getValue();
// if (action instanceof AttackAction) {
// ((AttackAction) action).setLevel(level);
// actionJson.put(Integer.toString(action.getId()), level);
// }
// userInfo.setActions(BaseJson.ObjectToJson(actionJson));
// }
// }
// }
//
// public void addExperience(int experience) {
// this.experience += experience;
// int _level = level;
// Integer _experience = levelExperience.get(_level);
// while (_experience != null && this.experience > _experience) {
// _level++;
// _experience = levelExperience.get(_level);
// }
// userInfo.setExperience(this.experience);
// upLevel(_level);
// RsyncManager.add(id, UserInfoRsync.class, userInfo);
// }
//
// public BasePosition gOldPosition() {
// return oldPosition;
// }
//
// public void sOldPosition(BasePosition oldPosition) {
// this.oldPosition = oldPosition;
// }
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/model/zone/DuelZone.java
// public class DuelZone extends BaseZone {
//
// public final static String ZONE_NAME = "DuelZone";
//
// public DuelZone() {
// super(ZONE_NAME);
// }
//
// @Override
// public void init() {
//
// }
//
// public void addPlayer(Player player) {
// player.sOldPosition(player.gPosition());
// super.addPlayer(player);
// }
//
// }
|
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import com.zhaidaosi.game.jgframework.handler.BaseHandlerChannel;
import com.zhaidaosi.game.jgframework.message.OutMessage;
import com.zhaidaosi.game.jgframework.model.action.IBaseAction;
import com.zhaidaosi.game.jgframework.model.entity.BasePlayer;
import com.zhaidaosi.game.server.model.player.Player;
import com.zhaidaosi.game.server.model.zone.DuelZone;
|
package com.zhaidaosi.game.server.model;
public class Duel {
public static final String END = "end";
public static final String INIT = "init";
public static final String MSG = "msg";
|
// Path: src/main/java/com/zhaidaosi/game/server/model/player/Player.java
// public class Player extends BasePlayer {
//
// private static Map<Integer, Integer> levelExperience = new HashMap<>();
//
// private UserInfo userInfo;
// private BasePosition oldPosition;
// private Map<String, Integer> actionJson = new HashMap<>();
//
// static {
// levelExperience.put(1, 100);
// levelExperience.put(2, 300);
// levelExperience.put(3, 500);
// }
//
// @SuppressWarnings("unchecked")
// public void init(UserInfo userInfo) {
// this.userInfo = userInfo;
// this.name = userInfo.getNickname();
// this.level = userInfo.getLevel();
// this.totalHp = this.level * 100;
// this.hp = this.totalHp;
// this.experience = userInfo.getExperience();
//
// actionJson = BaseJson.JsonToObject(userInfo.getActions(), Map.class);
//
// for (Map.Entry<String, Integer> entry : actionJson.entrySet()) {
// AttackAction attackAction = (AttackAction) ActionManager.getAction(Integer.parseInt(entry.getKey()));
// attackAction.setLevel(entry.getValue());
// this.addAction(attackAction);
// }
//
// IBaseArea area = AreaManager.getArea(Area.ID);
// area.addPlayer(this);
// }
//
// public UserInfo getUserInfo() {
// return userInfo;
// }
//
// private void upLevel(int level) {
// if (this.level != level) {
// this.level = level;
// userInfo.setLevel(level);
// for (Entry<Integer, IBaseAction> entry : actions.entrySet()) {
// IBaseAction action = entry.getValue();
// if (action instanceof AttackAction) {
// ((AttackAction) action).setLevel(level);
// actionJson.put(Integer.toString(action.getId()), level);
// }
// userInfo.setActions(BaseJson.ObjectToJson(actionJson));
// }
// }
// }
//
// public void addExperience(int experience) {
// this.experience += experience;
// int _level = level;
// Integer _experience = levelExperience.get(_level);
// while (_experience != null && this.experience > _experience) {
// _level++;
// _experience = levelExperience.get(_level);
// }
// userInfo.setExperience(this.experience);
// upLevel(_level);
// RsyncManager.add(id, UserInfoRsync.class, userInfo);
// }
//
// public BasePosition gOldPosition() {
// return oldPosition;
// }
//
// public void sOldPosition(BasePosition oldPosition) {
// this.oldPosition = oldPosition;
// }
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/model/zone/DuelZone.java
// public class DuelZone extends BaseZone {
//
// public final static String ZONE_NAME = "DuelZone";
//
// public DuelZone() {
// super(ZONE_NAME);
// }
//
// @Override
// public void init() {
//
// }
//
// public void addPlayer(Player player) {
// player.sOldPosition(player.gPosition());
// super.addPlayer(player);
// }
//
// }
// Path: src/main/java/com/zhaidaosi/game/server/model/Duel.java
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import com.zhaidaosi.game.jgframework.handler.BaseHandlerChannel;
import com.zhaidaosi.game.jgframework.message.OutMessage;
import com.zhaidaosi.game.jgframework.model.action.IBaseAction;
import com.zhaidaosi.game.jgframework.model.entity.BasePlayer;
import com.zhaidaosi.game.server.model.player.Player;
import com.zhaidaosi.game.server.model.zone.DuelZone;
package com.zhaidaosi.game.server.model;
public class Duel {
public static final String END = "end";
public static final String INIT = "init";
public static final String MSG = "msg";
|
public static Player doDuel(Player me, Player target, DuelZone zone, String handlerName) {
|
bupt1987/JgWeb
|
src/main/java/com/zhaidaosi/game/server/model/Duel.java
|
// Path: src/main/java/com/zhaidaosi/game/server/model/player/Player.java
// public class Player extends BasePlayer {
//
// private static Map<Integer, Integer> levelExperience = new HashMap<>();
//
// private UserInfo userInfo;
// private BasePosition oldPosition;
// private Map<String, Integer> actionJson = new HashMap<>();
//
// static {
// levelExperience.put(1, 100);
// levelExperience.put(2, 300);
// levelExperience.put(3, 500);
// }
//
// @SuppressWarnings("unchecked")
// public void init(UserInfo userInfo) {
// this.userInfo = userInfo;
// this.name = userInfo.getNickname();
// this.level = userInfo.getLevel();
// this.totalHp = this.level * 100;
// this.hp = this.totalHp;
// this.experience = userInfo.getExperience();
//
// actionJson = BaseJson.JsonToObject(userInfo.getActions(), Map.class);
//
// for (Map.Entry<String, Integer> entry : actionJson.entrySet()) {
// AttackAction attackAction = (AttackAction) ActionManager.getAction(Integer.parseInt(entry.getKey()));
// attackAction.setLevel(entry.getValue());
// this.addAction(attackAction);
// }
//
// IBaseArea area = AreaManager.getArea(Area.ID);
// area.addPlayer(this);
// }
//
// public UserInfo getUserInfo() {
// return userInfo;
// }
//
// private void upLevel(int level) {
// if (this.level != level) {
// this.level = level;
// userInfo.setLevel(level);
// for (Entry<Integer, IBaseAction> entry : actions.entrySet()) {
// IBaseAction action = entry.getValue();
// if (action instanceof AttackAction) {
// ((AttackAction) action).setLevel(level);
// actionJson.put(Integer.toString(action.getId()), level);
// }
// userInfo.setActions(BaseJson.ObjectToJson(actionJson));
// }
// }
// }
//
// public void addExperience(int experience) {
// this.experience += experience;
// int _level = level;
// Integer _experience = levelExperience.get(_level);
// while (_experience != null && this.experience > _experience) {
// _level++;
// _experience = levelExperience.get(_level);
// }
// userInfo.setExperience(this.experience);
// upLevel(_level);
// RsyncManager.add(id, UserInfoRsync.class, userInfo);
// }
//
// public BasePosition gOldPosition() {
// return oldPosition;
// }
//
// public void sOldPosition(BasePosition oldPosition) {
// this.oldPosition = oldPosition;
// }
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/model/zone/DuelZone.java
// public class DuelZone extends BaseZone {
//
// public final static String ZONE_NAME = "DuelZone";
//
// public DuelZone() {
// super(ZONE_NAME);
// }
//
// @Override
// public void init() {
//
// }
//
// public void addPlayer(Player player) {
// player.sOldPosition(player.gPosition());
// super.addPlayer(player);
// }
//
// }
|
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import com.zhaidaosi.game.jgframework.handler.BaseHandlerChannel;
import com.zhaidaosi.game.jgframework.message.OutMessage;
import com.zhaidaosi.game.jgframework.model.action.IBaseAction;
import com.zhaidaosi.game.jgframework.model.entity.BasePlayer;
import com.zhaidaosi.game.server.model.player.Player;
import com.zhaidaosi.game.server.model.zone.DuelZone;
|
package com.zhaidaosi.game.server.model;
public class Duel {
public static final String END = "end";
public static final String INIT = "init";
public static final String MSG = "msg";
|
// Path: src/main/java/com/zhaidaosi/game/server/model/player/Player.java
// public class Player extends BasePlayer {
//
// private static Map<Integer, Integer> levelExperience = new HashMap<>();
//
// private UserInfo userInfo;
// private BasePosition oldPosition;
// private Map<String, Integer> actionJson = new HashMap<>();
//
// static {
// levelExperience.put(1, 100);
// levelExperience.put(2, 300);
// levelExperience.put(3, 500);
// }
//
// @SuppressWarnings("unchecked")
// public void init(UserInfo userInfo) {
// this.userInfo = userInfo;
// this.name = userInfo.getNickname();
// this.level = userInfo.getLevel();
// this.totalHp = this.level * 100;
// this.hp = this.totalHp;
// this.experience = userInfo.getExperience();
//
// actionJson = BaseJson.JsonToObject(userInfo.getActions(), Map.class);
//
// for (Map.Entry<String, Integer> entry : actionJson.entrySet()) {
// AttackAction attackAction = (AttackAction) ActionManager.getAction(Integer.parseInt(entry.getKey()));
// attackAction.setLevel(entry.getValue());
// this.addAction(attackAction);
// }
//
// IBaseArea area = AreaManager.getArea(Area.ID);
// area.addPlayer(this);
// }
//
// public UserInfo getUserInfo() {
// return userInfo;
// }
//
// private void upLevel(int level) {
// if (this.level != level) {
// this.level = level;
// userInfo.setLevel(level);
// for (Entry<Integer, IBaseAction> entry : actions.entrySet()) {
// IBaseAction action = entry.getValue();
// if (action instanceof AttackAction) {
// ((AttackAction) action).setLevel(level);
// actionJson.put(Integer.toString(action.getId()), level);
// }
// userInfo.setActions(BaseJson.ObjectToJson(actionJson));
// }
// }
// }
//
// public void addExperience(int experience) {
// this.experience += experience;
// int _level = level;
// Integer _experience = levelExperience.get(_level);
// while (_experience != null && this.experience > _experience) {
// _level++;
// _experience = levelExperience.get(_level);
// }
// userInfo.setExperience(this.experience);
// upLevel(_level);
// RsyncManager.add(id, UserInfoRsync.class, userInfo);
// }
//
// public BasePosition gOldPosition() {
// return oldPosition;
// }
//
// public void sOldPosition(BasePosition oldPosition) {
// this.oldPosition = oldPosition;
// }
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/model/zone/DuelZone.java
// public class DuelZone extends BaseZone {
//
// public final static String ZONE_NAME = "DuelZone";
//
// public DuelZone() {
// super(ZONE_NAME);
// }
//
// @Override
// public void init() {
//
// }
//
// public void addPlayer(Player player) {
// player.sOldPosition(player.gPosition());
// super.addPlayer(player);
// }
//
// }
// Path: src/main/java/com/zhaidaosi/game/server/model/Duel.java
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import com.zhaidaosi.game.jgframework.handler.BaseHandlerChannel;
import com.zhaidaosi.game.jgframework.message.OutMessage;
import com.zhaidaosi.game.jgframework.model.action.IBaseAction;
import com.zhaidaosi.game.jgframework.model.entity.BasePlayer;
import com.zhaidaosi.game.server.model.player.Player;
import com.zhaidaosi.game.server.model.zone.DuelZone;
package com.zhaidaosi.game.server.model;
public class Duel {
public static final String END = "end";
public static final String INIT = "init";
public static final String MSG = "msg";
|
public static Player doDuel(Player me, Player target, DuelZone zone, String handlerName) {
|
bupt1987/JgWeb
|
src/main/java/com/zhaidaosi/game/server/BootStart.java
|
// Path: src/main/java/com/zhaidaosi/game/server/model/player/PlayerFactory.java
// public class PlayerFactory implements IBasePlayerFactory {
//
// public IBaseCharacter getPlayer() {
// return new Player();
// }
//
// }
|
import javax.servlet.http.HttpServlet;
import com.zhaidaosi.game.jgframework.Boot;
import com.zhaidaosi.game.server.model.player.PlayerFactory;
|
package com.zhaidaosi.game.server;
@SuppressWarnings("serial")
public class BootStart extends HttpServlet {
private static void start() {
//设置action所在包路径,不设置不扫描
Boot.setActionPackage("com.zhaidaosi.game.server.model.action");
//设置area所在包路径,不设置不扫描
Boot.setAreaPackage("com.zhaidaosi.game.server.model.area");
//设置player工厂,默认为BasePlayerFactory
|
// Path: src/main/java/com/zhaidaosi/game/server/model/player/PlayerFactory.java
// public class PlayerFactory implements IBasePlayerFactory {
//
// public IBaseCharacter getPlayer() {
// return new Player();
// }
//
// }
// Path: src/main/java/com/zhaidaosi/game/server/BootStart.java
import javax.servlet.http.HttpServlet;
import com.zhaidaosi.game.jgframework.Boot;
import com.zhaidaosi.game.server.model.player.PlayerFactory;
package com.zhaidaosi.game.server;
@SuppressWarnings("serial")
public class BootStart extends HttpServlet {
private static void start() {
//设置action所在包路径,不设置不扫描
Boot.setActionPackage("com.zhaidaosi.game.server.model.action");
//设置area所在包路径,不设置不扫描
Boot.setAreaPackage("com.zhaidaosi.game.server.model.area");
//设置player工厂,默认为BasePlayerFactory
|
Boot.setPlayerFactory(new PlayerFactory());
|
bupt1987/JgWeb
|
src/test/java/client/TestMaxUser.java
|
// Path: src/test/java/model/AuthResult.java
// public class AuthResult {
// public String address;
// public String secret;
//
// public AuthResult(String address, String secret) {
// this.address = address;
// this.secret = secret;
// }
// }
//
// Path: src/test/java/model/MyWebSocketClient.java
// public class MyWebSocketClient extends WebSocketClient {
//
// private boolean received = false;
// private String message;
//
// public MyWebSocketClient(URI serverUri, Draft draft) {
// super(serverUri, draft);
// }
//
// public MyWebSocketClient(URI serverURI) {
// super(serverURI);
// }
//
// public String getMessage() {
// return message;
// }
//
// @Override
// public void send(String text) throws NotYetConnectedException {
// synchronized (this) {
// super.send(text);
// while (!received) {
// try {
// this.wait();
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
// received = false;
// }
// }
//
// @Override
// public void onOpen(ServerHandshake handshakedata) {
// // System.out.println( "opened connection" );
// // if you plan to refuse connection based on ip or httpfields overload: onWebsocketHandshakeReceivedAsClient
// }
//
// @Override
// public void onMessage(String message) {
// this.message = message;
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// public void onFragment(Framedata fragment) {
// System.out.println("received fragment: " + new String(fragment.getPayloadData().array()));
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// @Override
// public void onClose(int code, String reason, boolean remote) {
// // The codecodes are documented in class org.java_websocket.framing.CloseFrame
// // System.out.println( "Connection closed by " + ( remote ? "remote peer" : "us" ) );
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// @Override
// public void onError(Exception ex) {
// ex.printStackTrace();
// // if the error is fatal then onClose will be called additionally
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// }
|
import com.zhaidaosi.game.jgframework.message.InMessage;
import com.zhaidaosi.game.jgframework.session.SessionManager;
import model.AuthResult;
import model.MyWebSocketClient;
import org.java_websocket.drafts.Draft_17;
import java.net.URI;
|
package client;
public class TestMaxUser {
private final URI uri;
private String sercret;
public TestMaxUser(URI uri, String sercret) {
this.uri = uri;
this.sercret = sercret;
}
public void run() throws Exception {
long startTime = System.currentTimeMillis();
|
// Path: src/test/java/model/AuthResult.java
// public class AuthResult {
// public String address;
// public String secret;
//
// public AuthResult(String address, String secret) {
// this.address = address;
// this.secret = secret;
// }
// }
//
// Path: src/test/java/model/MyWebSocketClient.java
// public class MyWebSocketClient extends WebSocketClient {
//
// private boolean received = false;
// private String message;
//
// public MyWebSocketClient(URI serverUri, Draft draft) {
// super(serverUri, draft);
// }
//
// public MyWebSocketClient(URI serverURI) {
// super(serverURI);
// }
//
// public String getMessage() {
// return message;
// }
//
// @Override
// public void send(String text) throws NotYetConnectedException {
// synchronized (this) {
// super.send(text);
// while (!received) {
// try {
// this.wait();
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
// received = false;
// }
// }
//
// @Override
// public void onOpen(ServerHandshake handshakedata) {
// // System.out.println( "opened connection" );
// // if you plan to refuse connection based on ip or httpfields overload: onWebsocketHandshakeReceivedAsClient
// }
//
// @Override
// public void onMessage(String message) {
// this.message = message;
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// public void onFragment(Framedata fragment) {
// System.out.println("received fragment: " + new String(fragment.getPayloadData().array()));
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// @Override
// public void onClose(int code, String reason, boolean remote) {
// // The codecodes are documented in class org.java_websocket.framing.CloseFrame
// // System.out.println( "Connection closed by " + ( remote ? "remote peer" : "us" ) );
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// @Override
// public void onError(Exception ex) {
// ex.printStackTrace();
// // if the error is fatal then onClose will be called additionally
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// }
// Path: src/test/java/client/TestMaxUser.java
import com.zhaidaosi.game.jgframework.message.InMessage;
import com.zhaidaosi.game.jgframework.session.SessionManager;
import model.AuthResult;
import model.MyWebSocketClient;
import org.java_websocket.drafts.Draft_17;
import java.net.URI;
package client;
public class TestMaxUser {
private final URI uri;
private String sercret;
public TestMaxUser(URI uri, String sercret) {
this.uri = uri;
this.sercret = sercret;
}
public void run() throws Exception {
long startTime = System.currentTimeMillis();
|
MyWebSocketClient ch = new MyWebSocketClient(uri, new Draft_17());
|
bupt1987/JgWeb
|
src/test/java/client/TestMaxUser.java
|
// Path: src/test/java/model/AuthResult.java
// public class AuthResult {
// public String address;
// public String secret;
//
// public AuthResult(String address, String secret) {
// this.address = address;
// this.secret = secret;
// }
// }
//
// Path: src/test/java/model/MyWebSocketClient.java
// public class MyWebSocketClient extends WebSocketClient {
//
// private boolean received = false;
// private String message;
//
// public MyWebSocketClient(URI serverUri, Draft draft) {
// super(serverUri, draft);
// }
//
// public MyWebSocketClient(URI serverURI) {
// super(serverURI);
// }
//
// public String getMessage() {
// return message;
// }
//
// @Override
// public void send(String text) throws NotYetConnectedException {
// synchronized (this) {
// super.send(text);
// while (!received) {
// try {
// this.wait();
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
// received = false;
// }
// }
//
// @Override
// public void onOpen(ServerHandshake handshakedata) {
// // System.out.println( "opened connection" );
// // if you plan to refuse connection based on ip or httpfields overload: onWebsocketHandshakeReceivedAsClient
// }
//
// @Override
// public void onMessage(String message) {
// this.message = message;
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// public void onFragment(Framedata fragment) {
// System.out.println("received fragment: " + new String(fragment.getPayloadData().array()));
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// @Override
// public void onClose(int code, String reason, boolean remote) {
// // The codecodes are documented in class org.java_websocket.framing.CloseFrame
// // System.out.println( "Connection closed by " + ( remote ? "remote peer" : "us" ) );
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// @Override
// public void onError(Exception ex) {
// ex.printStackTrace();
// // if the error is fatal then onClose will be called additionally
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// }
|
import com.zhaidaosi.game.jgframework.message.InMessage;
import com.zhaidaosi.game.jgframework.session.SessionManager;
import model.AuthResult;
import model.MyWebSocketClient;
import org.java_websocket.drafts.Draft_17;
import java.net.URI;
|
long endTime = System.currentTimeMillis();
System.out.println("end time : " + endTime + " | run time :" + (endTime - startTime));
}
public static void main(String[] args) throws Exception {
long startTime = System.currentTimeMillis();
System.out.println(startTime);
for (int i = 1; i <= 60000; i++) {
MaxUserThread t = new MaxUserThread("test" + i, "123456");
t.start();
Thread.sleep(10);
}
}
}
class MaxUserThread extends Thread {
String username;
String password;
public MaxUserThread(String username, String password) {
this.username = username;
this.password = password;
System.out.println(username);
}
@Override
public void run() {
try {
|
// Path: src/test/java/model/AuthResult.java
// public class AuthResult {
// public String address;
// public String secret;
//
// public AuthResult(String address, String secret) {
// this.address = address;
// this.secret = secret;
// }
// }
//
// Path: src/test/java/model/MyWebSocketClient.java
// public class MyWebSocketClient extends WebSocketClient {
//
// private boolean received = false;
// private String message;
//
// public MyWebSocketClient(URI serverUri, Draft draft) {
// super(serverUri, draft);
// }
//
// public MyWebSocketClient(URI serverURI) {
// super(serverURI);
// }
//
// public String getMessage() {
// return message;
// }
//
// @Override
// public void send(String text) throws NotYetConnectedException {
// synchronized (this) {
// super.send(text);
// while (!received) {
// try {
// this.wait();
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
// received = false;
// }
// }
//
// @Override
// public void onOpen(ServerHandshake handshakedata) {
// // System.out.println( "opened connection" );
// // if you plan to refuse connection based on ip or httpfields overload: onWebsocketHandshakeReceivedAsClient
// }
//
// @Override
// public void onMessage(String message) {
// this.message = message;
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// public void onFragment(Framedata fragment) {
// System.out.println("received fragment: " + new String(fragment.getPayloadData().array()));
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// @Override
// public void onClose(int code, String reason, boolean remote) {
// // The codecodes are documented in class org.java_websocket.framing.CloseFrame
// // System.out.println( "Connection closed by " + ( remote ? "remote peer" : "us" ) );
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// @Override
// public void onError(Exception ex) {
// ex.printStackTrace();
// // if the error is fatal then onClose will be called additionally
// synchronized (this) {
// received = true;
// this.notify();
// }
// }
//
// }
// Path: src/test/java/client/TestMaxUser.java
import com.zhaidaosi.game.jgframework.message.InMessage;
import com.zhaidaosi.game.jgframework.session.SessionManager;
import model.AuthResult;
import model.MyWebSocketClient;
import org.java_websocket.drafts.Draft_17;
import java.net.URI;
long endTime = System.currentTimeMillis();
System.out.println("end time : " + endTime + " | run time :" + (endTime - startTime));
}
public static void main(String[] args) throws Exception {
long startTime = System.currentTimeMillis();
System.out.println(startTime);
for (int i = 1; i <= 60000; i++) {
MaxUserThread t = new MaxUserThread("test" + i, "123456");
t.start();
Thread.sleep(10);
}
}
}
class MaxUserThread extends Thread {
String username;
String password;
public MaxUserThread(String username, String password) {
this.username = username;
this.password = password;
System.out.println(username);
}
@Override
public void run() {
try {
|
AuthResult ar = TestAuth.auth(username, password);
|
bupt1987/JgWeb
|
src/main/java/com/zhaidaosi/game/server/handler/SendMsgHandler.java
|
// Path: src/main/java/com/zhaidaosi/game/server/model/player/Player.java
// public class Player extends BasePlayer {
//
// private static Map<Integer, Integer> levelExperience = new HashMap<>();
//
// private UserInfo userInfo;
// private BasePosition oldPosition;
// private Map<String, Integer> actionJson = new HashMap<>();
//
// static {
// levelExperience.put(1, 100);
// levelExperience.put(2, 300);
// levelExperience.put(3, 500);
// }
//
// @SuppressWarnings("unchecked")
// public void init(UserInfo userInfo) {
// this.userInfo = userInfo;
// this.name = userInfo.getNickname();
// this.level = userInfo.getLevel();
// this.totalHp = this.level * 100;
// this.hp = this.totalHp;
// this.experience = userInfo.getExperience();
//
// actionJson = BaseJson.JsonToObject(userInfo.getActions(), Map.class);
//
// for (Map.Entry<String, Integer> entry : actionJson.entrySet()) {
// AttackAction attackAction = (AttackAction) ActionManager.getAction(Integer.parseInt(entry.getKey()));
// attackAction.setLevel(entry.getValue());
// this.addAction(attackAction);
// }
//
// IBaseArea area = AreaManager.getArea(Area.ID);
// area.addPlayer(this);
// }
//
// public UserInfo getUserInfo() {
// return userInfo;
// }
//
// private void upLevel(int level) {
// if (this.level != level) {
// this.level = level;
// userInfo.setLevel(level);
// for (Entry<Integer, IBaseAction> entry : actions.entrySet()) {
// IBaseAction action = entry.getValue();
// if (action instanceof AttackAction) {
// ((AttackAction) action).setLevel(level);
// actionJson.put(Integer.toString(action.getId()), level);
// }
// userInfo.setActions(BaseJson.ObjectToJson(actionJson));
// }
// }
// }
//
// public void addExperience(int experience) {
// this.experience += experience;
// int _level = level;
// Integer _experience = levelExperience.get(_level);
// while (_experience != null && this.experience > _experience) {
// _level++;
// _experience = levelExperience.get(_level);
// }
// userInfo.setExperience(this.experience);
// upLevel(_level);
// RsyncManager.add(id, UserInfoRsync.class, userInfo);
// }
//
// public BasePosition gOldPosition() {
// return oldPosition;
// }
//
// public void sOldPosition(BasePosition oldPosition) {
// this.oldPosition = oldPosition;
// }
//
// }
|
import java.util.HashMap;
import java.util.Map;
import com.zhaidaosi.game.jgframework.connector.IBaseConnector;
import com.zhaidaosi.game.jgframework.handler.BaseHandler;
import com.zhaidaosi.game.jgframework.message.IBaseMessage;
import com.zhaidaosi.game.jgframework.message.InMessage;
import com.zhaidaosi.game.jgframework.message.OutMessage;
import com.zhaidaosi.game.jgframework.model.area.IBaseArea;
import com.zhaidaosi.game.server.model.player.Player;
import io.netty.channel.Channel;
|
package com.zhaidaosi.game.server.handler;
public class SendMsgHandler extends BaseHandler {
@Override
public IBaseMessage run(InMessage im, Channel ch) {
Object msg = im.getMember("msg");
if (msg == null || msg.equals("")) {
return OutMessage.showError("msg 不能为空");
}
|
// Path: src/main/java/com/zhaidaosi/game/server/model/player/Player.java
// public class Player extends BasePlayer {
//
// private static Map<Integer, Integer> levelExperience = new HashMap<>();
//
// private UserInfo userInfo;
// private BasePosition oldPosition;
// private Map<String, Integer> actionJson = new HashMap<>();
//
// static {
// levelExperience.put(1, 100);
// levelExperience.put(2, 300);
// levelExperience.put(3, 500);
// }
//
// @SuppressWarnings("unchecked")
// public void init(UserInfo userInfo) {
// this.userInfo = userInfo;
// this.name = userInfo.getNickname();
// this.level = userInfo.getLevel();
// this.totalHp = this.level * 100;
// this.hp = this.totalHp;
// this.experience = userInfo.getExperience();
//
// actionJson = BaseJson.JsonToObject(userInfo.getActions(), Map.class);
//
// for (Map.Entry<String, Integer> entry : actionJson.entrySet()) {
// AttackAction attackAction = (AttackAction) ActionManager.getAction(Integer.parseInt(entry.getKey()));
// attackAction.setLevel(entry.getValue());
// this.addAction(attackAction);
// }
//
// IBaseArea area = AreaManager.getArea(Area.ID);
// area.addPlayer(this);
// }
//
// public UserInfo getUserInfo() {
// return userInfo;
// }
//
// private void upLevel(int level) {
// if (this.level != level) {
// this.level = level;
// userInfo.setLevel(level);
// for (Entry<Integer, IBaseAction> entry : actions.entrySet()) {
// IBaseAction action = entry.getValue();
// if (action instanceof AttackAction) {
// ((AttackAction) action).setLevel(level);
// actionJson.put(Integer.toString(action.getId()), level);
// }
// userInfo.setActions(BaseJson.ObjectToJson(actionJson));
// }
// }
// }
//
// public void addExperience(int experience) {
// this.experience += experience;
// int _level = level;
// Integer _experience = levelExperience.get(_level);
// while (_experience != null && this.experience > _experience) {
// _level++;
// _experience = levelExperience.get(_level);
// }
// userInfo.setExperience(this.experience);
// upLevel(_level);
// RsyncManager.add(id, UserInfoRsync.class, userInfo);
// }
//
// public BasePosition gOldPosition() {
// return oldPosition;
// }
//
// public void sOldPosition(BasePosition oldPosition) {
// this.oldPosition = oldPosition;
// }
//
// }
// Path: src/main/java/com/zhaidaosi/game/server/handler/SendMsgHandler.java
import java.util.HashMap;
import java.util.Map;
import com.zhaidaosi.game.jgframework.connector.IBaseConnector;
import com.zhaidaosi.game.jgframework.handler.BaseHandler;
import com.zhaidaosi.game.jgframework.message.IBaseMessage;
import com.zhaidaosi.game.jgframework.message.InMessage;
import com.zhaidaosi.game.jgframework.message.OutMessage;
import com.zhaidaosi.game.jgframework.model.area.IBaseArea;
import com.zhaidaosi.game.server.model.player.Player;
import io.netty.channel.Channel;
package com.zhaidaosi.game.server.handler;
public class SendMsgHandler extends BaseHandler {
@Override
public IBaseMessage run(InMessage im, Channel ch) {
Object msg = im.getMember("msg");
if (msg == null || msg.equals("")) {
return OutMessage.showError("msg 不能为空");
}
|
Player player = (Player) ch.attr(IBaseConnector.PLAYER).get();
|
bupt1987/JgWeb
|
src/main/java/com/zhaidaosi/game/server/handler/auth/LoginHandler.java
|
// Path: src/main/java/com/zhaidaosi/game/server/rsync/UserRsync.java
// public class UserRsync extends BaseRsync {
//
// private static final Logger log = LoggerFactory.getLogger(UserRsync.class);
//
// @Override
// public void runRsync() {
// UserService service = (UserService) ServiceManager.getService(UserService.BEAN_ID);
// for (Map.Entry<Integer, IBaseModel> entry : rsyncMap.entrySet()) {
// User user = (User) entry.getValue();
// service.update(user);
// log.info("rsync => " + user);
// }
// }
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/sdm/model/User.java
// @SuppressWarnings("serial")
// @Entity
// @Table(name = "user", catalog = "jgframework")
// public class User extends BaseModel {
//
// // Fields
//
// private Integer id;
// private String username;
// private String password;
// private Long lastLoginTime;
// private Long creatTime;
//
// // Constructors
//
// /** default constructor */
// public User() {
// }
//
// /** full constructor */
// public User(String username, String password, Long lastLoginTime, Long creatTime) {
// this.username = username;
// this.password = password;
// this.lastLoginTime = lastLoginTime;
// this.creatTime = creatTime;
// }
//
// // Property accessors
// @Id
// @GeneratedValue(strategy = IDENTITY)
// @Column(name = "id", unique = true, nullable = false)
// public Integer getId() {
// return this.id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// @Column(name = "username", nullable = false, length = 30)
// public String getUsername() {
// return this.username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// @Column(name = "password", nullable = false, length = 50)
// public String getPassword() {
// return this.password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// @Column(name = "last_login_time", nullable = false)
// public Long getLastLoginTime() {
// return this.lastLoginTime;
// }
//
// public void setLastLoginTime(Long lastLoginTime) {
// this.lastLoginTime = lastLoginTime;
// }
//
// @Column(name = "creat_time", nullable = false)
// public Long getCreatTime() {
// return this.creatTime;
// }
//
// public void setCreatTime(Long creatTime) {
// this.creatTime = creatTime;
// }
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/sdm/service/UserService.java
// public class UserService extends BaseService {
//
// public final static String BEAN_ID = "userService";
//
// private static BaseLocalCached cached = new BaseLocalCached();
//
// @Autowired
// protected UserDAO dao;
//
// @Autowired
// protected UserInfoDAO userInfoDao;
//
// @PostConstruct
// protected void setDao() {
// super.setDao(dao);
// }
//
// public User findByUserName(String username) {
// String cacheKey = "findByUserName_" + username;
// Object user = cached.get(cacheKey);
// if (cached.checkInvalid(user)) {
// List<?> list = super.findByProperty(UserDAO.USERNAME, username);
// if (list.size() > 0) {
// user = list.get(0);
// } else {
// user = null;
// }
// cached.set("UserService_findByUserName_" + username, list, 300);
// }
// return user == null ? null : (User) user;
// }
//
// public void addUser(String username, String password, String nickName) {
// User user = new User();
// user.setUsername(username);
// user.setPassword(BaseMd5.encrypt(username + password));
// user.setCreatTime(System.currentTimeMillis());
// user.setLastLoginTime(0L);
// dao.save(user);
//
// UserInfo userinfo = new UserInfo();
// userinfo.setActions(UserInfoService.getDefaultActions());
// userinfo.setExperience(0);
// userinfo.setLevel(1);
// userinfo.setNickname(nickName);
// userinfo.setUid(user.getId());
// userInfoDao.save(userinfo);
// }
//
//
// }
|
import java.util.HashMap;
import com.zhaidaosi.game.jgframework.Boot;
import com.zhaidaosi.game.jgframework.common.BaseString;
import com.zhaidaosi.game.jgframework.common.encrpt.BaseMd5;
import com.zhaidaosi.game.jgframework.common.spring.ServiceManager;
import com.zhaidaosi.game.jgframework.connector.AuthConnector;
import com.zhaidaosi.game.jgframework.handler.BaseHandler;
import com.zhaidaosi.game.jgframework.message.IBaseMessage;
import com.zhaidaosi.game.jgframework.message.InMessage;
import com.zhaidaosi.game.jgframework.message.OutMessage;
import com.zhaidaosi.game.jgframework.rsync.RsyncManager;
import com.zhaidaosi.game.jgframework.session.SessionManager;
import com.zhaidaosi.game.server.rsync.UserRsync;
import com.zhaidaosi.game.server.sdm.model.User;
import com.zhaidaosi.game.server.sdm.service.UserService;
import io.netty.channel.Channel;
|
package com.zhaidaosi.game.server.handler.auth;
public class LoginHandler extends BaseHandler {
UserService userService = (UserService) ServiceManager.getService(UserService.BEAN_ID);
@Override
public IBaseMessage run(InMessage im, Channel ch) throws Exception {
HashMap<String, Object> args = im.getP();
String username = (String) args.get("username");
String password = (String) args.get("password");
if (!BaseString.isEmpty(username)
&& !BaseString.isEmpty(password)) {
|
// Path: src/main/java/com/zhaidaosi/game/server/rsync/UserRsync.java
// public class UserRsync extends BaseRsync {
//
// private static final Logger log = LoggerFactory.getLogger(UserRsync.class);
//
// @Override
// public void runRsync() {
// UserService service = (UserService) ServiceManager.getService(UserService.BEAN_ID);
// for (Map.Entry<Integer, IBaseModel> entry : rsyncMap.entrySet()) {
// User user = (User) entry.getValue();
// service.update(user);
// log.info("rsync => " + user);
// }
// }
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/sdm/model/User.java
// @SuppressWarnings("serial")
// @Entity
// @Table(name = "user", catalog = "jgframework")
// public class User extends BaseModel {
//
// // Fields
//
// private Integer id;
// private String username;
// private String password;
// private Long lastLoginTime;
// private Long creatTime;
//
// // Constructors
//
// /** default constructor */
// public User() {
// }
//
// /** full constructor */
// public User(String username, String password, Long lastLoginTime, Long creatTime) {
// this.username = username;
// this.password = password;
// this.lastLoginTime = lastLoginTime;
// this.creatTime = creatTime;
// }
//
// // Property accessors
// @Id
// @GeneratedValue(strategy = IDENTITY)
// @Column(name = "id", unique = true, nullable = false)
// public Integer getId() {
// return this.id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// @Column(name = "username", nullable = false, length = 30)
// public String getUsername() {
// return this.username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// @Column(name = "password", nullable = false, length = 50)
// public String getPassword() {
// return this.password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// @Column(name = "last_login_time", nullable = false)
// public Long getLastLoginTime() {
// return this.lastLoginTime;
// }
//
// public void setLastLoginTime(Long lastLoginTime) {
// this.lastLoginTime = lastLoginTime;
// }
//
// @Column(name = "creat_time", nullable = false)
// public Long getCreatTime() {
// return this.creatTime;
// }
//
// public void setCreatTime(Long creatTime) {
// this.creatTime = creatTime;
// }
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/sdm/service/UserService.java
// public class UserService extends BaseService {
//
// public final static String BEAN_ID = "userService";
//
// private static BaseLocalCached cached = new BaseLocalCached();
//
// @Autowired
// protected UserDAO dao;
//
// @Autowired
// protected UserInfoDAO userInfoDao;
//
// @PostConstruct
// protected void setDao() {
// super.setDao(dao);
// }
//
// public User findByUserName(String username) {
// String cacheKey = "findByUserName_" + username;
// Object user = cached.get(cacheKey);
// if (cached.checkInvalid(user)) {
// List<?> list = super.findByProperty(UserDAO.USERNAME, username);
// if (list.size() > 0) {
// user = list.get(0);
// } else {
// user = null;
// }
// cached.set("UserService_findByUserName_" + username, list, 300);
// }
// return user == null ? null : (User) user;
// }
//
// public void addUser(String username, String password, String nickName) {
// User user = new User();
// user.setUsername(username);
// user.setPassword(BaseMd5.encrypt(username + password));
// user.setCreatTime(System.currentTimeMillis());
// user.setLastLoginTime(0L);
// dao.save(user);
//
// UserInfo userinfo = new UserInfo();
// userinfo.setActions(UserInfoService.getDefaultActions());
// userinfo.setExperience(0);
// userinfo.setLevel(1);
// userinfo.setNickname(nickName);
// userinfo.setUid(user.getId());
// userInfoDao.save(userinfo);
// }
//
//
// }
// Path: src/main/java/com/zhaidaosi/game/server/handler/auth/LoginHandler.java
import java.util.HashMap;
import com.zhaidaosi.game.jgframework.Boot;
import com.zhaidaosi.game.jgframework.common.BaseString;
import com.zhaidaosi.game.jgframework.common.encrpt.BaseMd5;
import com.zhaidaosi.game.jgframework.common.spring.ServiceManager;
import com.zhaidaosi.game.jgframework.connector.AuthConnector;
import com.zhaidaosi.game.jgframework.handler.BaseHandler;
import com.zhaidaosi.game.jgframework.message.IBaseMessage;
import com.zhaidaosi.game.jgframework.message.InMessage;
import com.zhaidaosi.game.jgframework.message.OutMessage;
import com.zhaidaosi.game.jgframework.rsync.RsyncManager;
import com.zhaidaosi.game.jgframework.session.SessionManager;
import com.zhaidaosi.game.server.rsync.UserRsync;
import com.zhaidaosi.game.server.sdm.model.User;
import com.zhaidaosi.game.server.sdm.service.UserService;
import io.netty.channel.Channel;
package com.zhaidaosi.game.server.handler.auth;
public class LoginHandler extends BaseHandler {
UserService userService = (UserService) ServiceManager.getService(UserService.BEAN_ID);
@Override
public IBaseMessage run(InMessage im, Channel ch) throws Exception {
HashMap<String, Object> args = im.getP();
String username = (String) args.get("username");
String password = (String) args.get("password");
if (!BaseString.isEmpty(username)
&& !BaseString.isEmpty(password)) {
|
User user = userService.findByUserName(username);
|
bupt1987/JgWeb
|
src/main/java/com/zhaidaosi/game/server/sdm/service/UserInfoService.java
|
// Path: src/main/java/com/zhaidaosi/game/server/model/action/AttackAction.java
// public class AttackAction extends BaseAction {
//
// public static int ID = 1;
//
// private int level = 1;
//
// private int minDamage;
//
// private int maxDamage;
//
// public AttackAction() {
// super(ID, "基本攻击");
// }
//
// @Override
// public void doAction(Object self, Object target, BaseHandlerChannel ch) {
// Player selfPlayer = (Player) self;
// Player targetPlayer = (Player) target;
// int damage = minDamage + new java.util.Random().nextInt(maxDamage - minDamage);
// targetPlayer.setHp(targetPlayer.getHp() - damage);
// if (targetPlayer.getHp() < 0) {
// targetPlayer.setHp(0);
// }
// String format = "%1$s 使用 %2$s(%3$d级) 攻击 %4$s 造成 %5$d 点伤害";
// String msg = String.format(format, selfPlayer.getName(), this.getName(), this.getLevel(), targetPlayer.getName(), damage);
// ch.writeGroup(Duel.write(msg, Duel.MSG, self, target));
// }
//
// public int getMinDamage() {
// return minDamage;
// }
//
// public void setMinDamage(int minDamage) {
// this.minDamage = minDamage;
// }
//
// public int getMaxDamage() {
// return maxDamage;
// }
//
// public void setMaxDamage(int maxDamage) {
// this.maxDamage = maxDamage;
// }
//
// public int getLevel() {
// return level;
// }
//
// public void setLevel(int level) {
// this.level = level;
// this.maxDamage = 30 * level;
// this.minDamage = 15 * level;
// }
//
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/rsync/UserInfoRsync.java
// public class UserInfoRsync extends BaseRsync {
//
// private static final Logger log = LoggerFactory.getLogger(UserInfoRsync.class);
//
// @Override
// public void runRsync() {
// UserInfoService service = (UserInfoService) ServiceManager.getService(UserInfoService.BEAN_ID);
// for (Map.Entry<Integer, IBaseModel> entry : rsyncMap.entrySet()) {
// UserInfo userInfo = (UserInfo) entry.getValue();
// service.update(userInfo);
// log.info("rsync => " + userInfo);
// }
// }
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/sdm/dao/UserInfoDAO.java
// @Repository
// public class UserInfoDAO extends BaseDao {
// // property constants
// public static final String UID = "uid";
// public static final String NICKNAME = "nickname";
// public static final String LEVEL = "level";
// public static final String EXPERIENCE = "experience";
// public static final String ACTIONS = "actions";
//
// public UserInfoDAO() {
// super.setTableName("user_info");
// super.setModelName("UserInfo");
// }
//
// }
|
import java.util.HashMap;
import java.util.Map;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import com.zhaidaosi.game.jgframework.common.BaseJson;
import com.zhaidaosi.game.jgframework.common.sdm.BaseService;
import com.zhaidaosi.game.jgframework.common.sdm.IBaseModel;
import com.zhaidaosi.game.jgframework.rsync.RsyncManager;
import com.zhaidaosi.game.server.model.action.AttackAction;
import com.zhaidaosi.game.server.rsync.UserInfoRsync;
import com.zhaidaosi.game.server.sdm.dao.UserInfoDAO;
|
package com.zhaidaosi.game.server.sdm.service;
public class UserInfoService extends BaseService {
public final static String BEAN_ID = "userInfoService";
@Autowired
|
// Path: src/main/java/com/zhaidaosi/game/server/model/action/AttackAction.java
// public class AttackAction extends BaseAction {
//
// public static int ID = 1;
//
// private int level = 1;
//
// private int minDamage;
//
// private int maxDamage;
//
// public AttackAction() {
// super(ID, "基本攻击");
// }
//
// @Override
// public void doAction(Object self, Object target, BaseHandlerChannel ch) {
// Player selfPlayer = (Player) self;
// Player targetPlayer = (Player) target;
// int damage = minDamage + new java.util.Random().nextInt(maxDamage - minDamage);
// targetPlayer.setHp(targetPlayer.getHp() - damage);
// if (targetPlayer.getHp() < 0) {
// targetPlayer.setHp(0);
// }
// String format = "%1$s 使用 %2$s(%3$d级) 攻击 %4$s 造成 %5$d 点伤害";
// String msg = String.format(format, selfPlayer.getName(), this.getName(), this.getLevel(), targetPlayer.getName(), damage);
// ch.writeGroup(Duel.write(msg, Duel.MSG, self, target));
// }
//
// public int getMinDamage() {
// return minDamage;
// }
//
// public void setMinDamage(int minDamage) {
// this.minDamage = minDamage;
// }
//
// public int getMaxDamage() {
// return maxDamage;
// }
//
// public void setMaxDamage(int maxDamage) {
// this.maxDamage = maxDamage;
// }
//
// public int getLevel() {
// return level;
// }
//
// public void setLevel(int level) {
// this.level = level;
// this.maxDamage = 30 * level;
// this.minDamage = 15 * level;
// }
//
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/rsync/UserInfoRsync.java
// public class UserInfoRsync extends BaseRsync {
//
// private static final Logger log = LoggerFactory.getLogger(UserInfoRsync.class);
//
// @Override
// public void runRsync() {
// UserInfoService service = (UserInfoService) ServiceManager.getService(UserInfoService.BEAN_ID);
// for (Map.Entry<Integer, IBaseModel> entry : rsyncMap.entrySet()) {
// UserInfo userInfo = (UserInfo) entry.getValue();
// service.update(userInfo);
// log.info("rsync => " + userInfo);
// }
// }
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/sdm/dao/UserInfoDAO.java
// @Repository
// public class UserInfoDAO extends BaseDao {
// // property constants
// public static final String UID = "uid";
// public static final String NICKNAME = "nickname";
// public static final String LEVEL = "level";
// public static final String EXPERIENCE = "experience";
// public static final String ACTIONS = "actions";
//
// public UserInfoDAO() {
// super.setTableName("user_info");
// super.setModelName("UserInfo");
// }
//
// }
// Path: src/main/java/com/zhaidaosi/game/server/sdm/service/UserInfoService.java
import java.util.HashMap;
import java.util.Map;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import com.zhaidaosi.game.jgframework.common.BaseJson;
import com.zhaidaosi.game.jgframework.common.sdm.BaseService;
import com.zhaidaosi.game.jgframework.common.sdm.IBaseModel;
import com.zhaidaosi.game.jgframework.rsync.RsyncManager;
import com.zhaidaosi.game.server.model.action.AttackAction;
import com.zhaidaosi.game.server.rsync.UserInfoRsync;
import com.zhaidaosi.game.server.sdm.dao.UserInfoDAO;
package com.zhaidaosi.game.server.sdm.service;
public class UserInfoService extends BaseService {
public final static String BEAN_ID = "userInfoService";
@Autowired
|
protected UserInfoDAO dao;
|
bupt1987/JgWeb
|
src/main/java/com/zhaidaosi/game/server/sdm/service/UserInfoService.java
|
// Path: src/main/java/com/zhaidaosi/game/server/model/action/AttackAction.java
// public class AttackAction extends BaseAction {
//
// public static int ID = 1;
//
// private int level = 1;
//
// private int minDamage;
//
// private int maxDamage;
//
// public AttackAction() {
// super(ID, "基本攻击");
// }
//
// @Override
// public void doAction(Object self, Object target, BaseHandlerChannel ch) {
// Player selfPlayer = (Player) self;
// Player targetPlayer = (Player) target;
// int damage = minDamage + new java.util.Random().nextInt(maxDamage - minDamage);
// targetPlayer.setHp(targetPlayer.getHp() - damage);
// if (targetPlayer.getHp() < 0) {
// targetPlayer.setHp(0);
// }
// String format = "%1$s 使用 %2$s(%3$d级) 攻击 %4$s 造成 %5$d 点伤害";
// String msg = String.format(format, selfPlayer.getName(), this.getName(), this.getLevel(), targetPlayer.getName(), damage);
// ch.writeGroup(Duel.write(msg, Duel.MSG, self, target));
// }
//
// public int getMinDamage() {
// return minDamage;
// }
//
// public void setMinDamage(int minDamage) {
// this.minDamage = minDamage;
// }
//
// public int getMaxDamage() {
// return maxDamage;
// }
//
// public void setMaxDamage(int maxDamage) {
// this.maxDamage = maxDamage;
// }
//
// public int getLevel() {
// return level;
// }
//
// public void setLevel(int level) {
// this.level = level;
// this.maxDamage = 30 * level;
// this.minDamage = 15 * level;
// }
//
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/rsync/UserInfoRsync.java
// public class UserInfoRsync extends BaseRsync {
//
// private static final Logger log = LoggerFactory.getLogger(UserInfoRsync.class);
//
// @Override
// public void runRsync() {
// UserInfoService service = (UserInfoService) ServiceManager.getService(UserInfoService.BEAN_ID);
// for (Map.Entry<Integer, IBaseModel> entry : rsyncMap.entrySet()) {
// UserInfo userInfo = (UserInfo) entry.getValue();
// service.update(userInfo);
// log.info("rsync => " + userInfo);
// }
// }
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/sdm/dao/UserInfoDAO.java
// @Repository
// public class UserInfoDAO extends BaseDao {
// // property constants
// public static final String UID = "uid";
// public static final String NICKNAME = "nickname";
// public static final String LEVEL = "level";
// public static final String EXPERIENCE = "experience";
// public static final String ACTIONS = "actions";
//
// public UserInfoDAO() {
// super.setTableName("user_info");
// super.setModelName("UserInfo");
// }
//
// }
|
import java.util.HashMap;
import java.util.Map;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import com.zhaidaosi.game.jgframework.common.BaseJson;
import com.zhaidaosi.game.jgframework.common.sdm.BaseService;
import com.zhaidaosi.game.jgframework.common.sdm.IBaseModel;
import com.zhaidaosi.game.jgframework.rsync.RsyncManager;
import com.zhaidaosi.game.server.model.action.AttackAction;
import com.zhaidaosi.game.server.rsync.UserInfoRsync;
import com.zhaidaosi.game.server.sdm.dao.UserInfoDAO;
|
package com.zhaidaosi.game.server.sdm.service;
public class UserInfoService extends BaseService {
public final static String BEAN_ID = "userInfoService";
@Autowired
protected UserInfoDAO dao;
@PostConstruct
protected void setDao() {
super.setDao(dao);
}
public IBaseModel findByUid(int uid) {
|
// Path: src/main/java/com/zhaidaosi/game/server/model/action/AttackAction.java
// public class AttackAction extends BaseAction {
//
// public static int ID = 1;
//
// private int level = 1;
//
// private int minDamage;
//
// private int maxDamage;
//
// public AttackAction() {
// super(ID, "基本攻击");
// }
//
// @Override
// public void doAction(Object self, Object target, BaseHandlerChannel ch) {
// Player selfPlayer = (Player) self;
// Player targetPlayer = (Player) target;
// int damage = minDamage + new java.util.Random().nextInt(maxDamage - minDamage);
// targetPlayer.setHp(targetPlayer.getHp() - damage);
// if (targetPlayer.getHp() < 0) {
// targetPlayer.setHp(0);
// }
// String format = "%1$s 使用 %2$s(%3$d级) 攻击 %4$s 造成 %5$d 点伤害";
// String msg = String.format(format, selfPlayer.getName(), this.getName(), this.getLevel(), targetPlayer.getName(), damage);
// ch.writeGroup(Duel.write(msg, Duel.MSG, self, target));
// }
//
// public int getMinDamage() {
// return minDamage;
// }
//
// public void setMinDamage(int minDamage) {
// this.minDamage = minDamage;
// }
//
// public int getMaxDamage() {
// return maxDamage;
// }
//
// public void setMaxDamage(int maxDamage) {
// this.maxDamage = maxDamage;
// }
//
// public int getLevel() {
// return level;
// }
//
// public void setLevel(int level) {
// this.level = level;
// this.maxDamage = 30 * level;
// this.minDamage = 15 * level;
// }
//
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/rsync/UserInfoRsync.java
// public class UserInfoRsync extends BaseRsync {
//
// private static final Logger log = LoggerFactory.getLogger(UserInfoRsync.class);
//
// @Override
// public void runRsync() {
// UserInfoService service = (UserInfoService) ServiceManager.getService(UserInfoService.BEAN_ID);
// for (Map.Entry<Integer, IBaseModel> entry : rsyncMap.entrySet()) {
// UserInfo userInfo = (UserInfo) entry.getValue();
// service.update(userInfo);
// log.info("rsync => " + userInfo);
// }
// }
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/sdm/dao/UserInfoDAO.java
// @Repository
// public class UserInfoDAO extends BaseDao {
// // property constants
// public static final String UID = "uid";
// public static final String NICKNAME = "nickname";
// public static final String LEVEL = "level";
// public static final String EXPERIENCE = "experience";
// public static final String ACTIONS = "actions";
//
// public UserInfoDAO() {
// super.setTableName("user_info");
// super.setModelName("UserInfo");
// }
//
// }
// Path: src/main/java/com/zhaidaosi/game/server/sdm/service/UserInfoService.java
import java.util.HashMap;
import java.util.Map;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import com.zhaidaosi.game.jgframework.common.BaseJson;
import com.zhaidaosi.game.jgframework.common.sdm.BaseService;
import com.zhaidaosi.game.jgframework.common.sdm.IBaseModel;
import com.zhaidaosi.game.jgframework.rsync.RsyncManager;
import com.zhaidaosi.game.server.model.action.AttackAction;
import com.zhaidaosi.game.server.rsync.UserInfoRsync;
import com.zhaidaosi.game.server.sdm.dao.UserInfoDAO;
package com.zhaidaosi.game.server.sdm.service;
public class UserInfoService extends BaseService {
public final static String BEAN_ID = "userInfoService";
@Autowired
protected UserInfoDAO dao;
@PostConstruct
protected void setDao() {
super.setDao(dao);
}
public IBaseModel findByUid(int uid) {
|
IBaseModel model = RsyncManager.get(uid, UserInfoRsync.class);
|
bupt1987/JgWeb
|
src/main/java/com/zhaidaosi/game/server/sdm/service/UserInfoService.java
|
// Path: src/main/java/com/zhaidaosi/game/server/model/action/AttackAction.java
// public class AttackAction extends BaseAction {
//
// public static int ID = 1;
//
// private int level = 1;
//
// private int minDamage;
//
// private int maxDamage;
//
// public AttackAction() {
// super(ID, "基本攻击");
// }
//
// @Override
// public void doAction(Object self, Object target, BaseHandlerChannel ch) {
// Player selfPlayer = (Player) self;
// Player targetPlayer = (Player) target;
// int damage = minDamage + new java.util.Random().nextInt(maxDamage - minDamage);
// targetPlayer.setHp(targetPlayer.getHp() - damage);
// if (targetPlayer.getHp() < 0) {
// targetPlayer.setHp(0);
// }
// String format = "%1$s 使用 %2$s(%3$d级) 攻击 %4$s 造成 %5$d 点伤害";
// String msg = String.format(format, selfPlayer.getName(), this.getName(), this.getLevel(), targetPlayer.getName(), damage);
// ch.writeGroup(Duel.write(msg, Duel.MSG, self, target));
// }
//
// public int getMinDamage() {
// return minDamage;
// }
//
// public void setMinDamage(int minDamage) {
// this.minDamage = minDamage;
// }
//
// public int getMaxDamage() {
// return maxDamage;
// }
//
// public void setMaxDamage(int maxDamage) {
// this.maxDamage = maxDamage;
// }
//
// public int getLevel() {
// return level;
// }
//
// public void setLevel(int level) {
// this.level = level;
// this.maxDamage = 30 * level;
// this.minDamage = 15 * level;
// }
//
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/rsync/UserInfoRsync.java
// public class UserInfoRsync extends BaseRsync {
//
// private static final Logger log = LoggerFactory.getLogger(UserInfoRsync.class);
//
// @Override
// public void runRsync() {
// UserInfoService service = (UserInfoService) ServiceManager.getService(UserInfoService.BEAN_ID);
// for (Map.Entry<Integer, IBaseModel> entry : rsyncMap.entrySet()) {
// UserInfo userInfo = (UserInfo) entry.getValue();
// service.update(userInfo);
// log.info("rsync => " + userInfo);
// }
// }
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/sdm/dao/UserInfoDAO.java
// @Repository
// public class UserInfoDAO extends BaseDao {
// // property constants
// public static final String UID = "uid";
// public static final String NICKNAME = "nickname";
// public static final String LEVEL = "level";
// public static final String EXPERIENCE = "experience";
// public static final String ACTIONS = "actions";
//
// public UserInfoDAO() {
// super.setTableName("user_info");
// super.setModelName("UserInfo");
// }
//
// }
|
import java.util.HashMap;
import java.util.Map;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import com.zhaidaosi.game.jgframework.common.BaseJson;
import com.zhaidaosi.game.jgframework.common.sdm.BaseService;
import com.zhaidaosi.game.jgframework.common.sdm.IBaseModel;
import com.zhaidaosi.game.jgframework.rsync.RsyncManager;
import com.zhaidaosi.game.server.model.action.AttackAction;
import com.zhaidaosi.game.server.rsync.UserInfoRsync;
import com.zhaidaosi.game.server.sdm.dao.UserInfoDAO;
|
package com.zhaidaosi.game.server.sdm.service;
public class UserInfoService extends BaseService {
public final static String BEAN_ID = "userInfoService";
@Autowired
protected UserInfoDAO dao;
@PostConstruct
protected void setDao() {
super.setDao(dao);
}
public IBaseModel findByUid(int uid) {
IBaseModel model = RsyncManager.get(uid, UserInfoRsync.class);
if (model == null) {
model = super.findOneByProperty(UserInfoDAO.UID, uid);
}
return model;
}
public static String getDefaultActions() {
Map<String, Integer> actions = new HashMap<>();
|
// Path: src/main/java/com/zhaidaosi/game/server/model/action/AttackAction.java
// public class AttackAction extends BaseAction {
//
// public static int ID = 1;
//
// private int level = 1;
//
// private int minDamage;
//
// private int maxDamage;
//
// public AttackAction() {
// super(ID, "基本攻击");
// }
//
// @Override
// public void doAction(Object self, Object target, BaseHandlerChannel ch) {
// Player selfPlayer = (Player) self;
// Player targetPlayer = (Player) target;
// int damage = minDamage + new java.util.Random().nextInt(maxDamage - minDamage);
// targetPlayer.setHp(targetPlayer.getHp() - damage);
// if (targetPlayer.getHp() < 0) {
// targetPlayer.setHp(0);
// }
// String format = "%1$s 使用 %2$s(%3$d级) 攻击 %4$s 造成 %5$d 点伤害";
// String msg = String.format(format, selfPlayer.getName(), this.getName(), this.getLevel(), targetPlayer.getName(), damage);
// ch.writeGroup(Duel.write(msg, Duel.MSG, self, target));
// }
//
// public int getMinDamage() {
// return minDamage;
// }
//
// public void setMinDamage(int minDamage) {
// this.minDamage = minDamage;
// }
//
// public int getMaxDamage() {
// return maxDamage;
// }
//
// public void setMaxDamage(int maxDamage) {
// this.maxDamage = maxDamage;
// }
//
// public int getLevel() {
// return level;
// }
//
// public void setLevel(int level) {
// this.level = level;
// this.maxDamage = 30 * level;
// this.minDamage = 15 * level;
// }
//
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/rsync/UserInfoRsync.java
// public class UserInfoRsync extends BaseRsync {
//
// private static final Logger log = LoggerFactory.getLogger(UserInfoRsync.class);
//
// @Override
// public void runRsync() {
// UserInfoService service = (UserInfoService) ServiceManager.getService(UserInfoService.BEAN_ID);
// for (Map.Entry<Integer, IBaseModel> entry : rsyncMap.entrySet()) {
// UserInfo userInfo = (UserInfo) entry.getValue();
// service.update(userInfo);
// log.info("rsync => " + userInfo);
// }
// }
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/sdm/dao/UserInfoDAO.java
// @Repository
// public class UserInfoDAO extends BaseDao {
// // property constants
// public static final String UID = "uid";
// public static final String NICKNAME = "nickname";
// public static final String LEVEL = "level";
// public static final String EXPERIENCE = "experience";
// public static final String ACTIONS = "actions";
//
// public UserInfoDAO() {
// super.setTableName("user_info");
// super.setModelName("UserInfo");
// }
//
// }
// Path: src/main/java/com/zhaidaosi/game/server/sdm/service/UserInfoService.java
import java.util.HashMap;
import java.util.Map;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import com.zhaidaosi.game.jgframework.common.BaseJson;
import com.zhaidaosi.game.jgframework.common.sdm.BaseService;
import com.zhaidaosi.game.jgframework.common.sdm.IBaseModel;
import com.zhaidaosi.game.jgframework.rsync.RsyncManager;
import com.zhaidaosi.game.server.model.action.AttackAction;
import com.zhaidaosi.game.server.rsync.UserInfoRsync;
import com.zhaidaosi.game.server.sdm.dao.UserInfoDAO;
package com.zhaidaosi.game.server.sdm.service;
public class UserInfoService extends BaseService {
public final static String BEAN_ID = "userInfoService";
@Autowired
protected UserInfoDAO dao;
@PostConstruct
protected void setDao() {
super.setDao(dao);
}
public IBaseModel findByUid(int uid) {
IBaseModel model = RsyncManager.get(uid, UserInfoRsync.class);
if (model == null) {
model = super.findOneByProperty(UserInfoDAO.UID, uid);
}
return model;
}
public static String getDefaultActions() {
Map<String, Integer> actions = new HashMap<>();
|
actions.put(Integer.toString(AttackAction.ID), 1);
|
bupt1987/JgWeb
|
src/main/java/com/zhaidaosi/game/server/rsync/UserInfoRsync.java
|
// Path: src/main/java/com/zhaidaosi/game/server/sdm/model/UserInfo.java
// @SuppressWarnings("serial")
// @Entity
// @Table(name = "user_info", catalog = "jgframework", uniqueConstraints = @UniqueConstraint(columnNames = "uid"))
// public class UserInfo extends BaseModel {
//
// // Fields
//
// private Integer uid;
// private String nickname;
// private Integer level;
// private Integer experience;
// private String actions;
//
// // Constructors
//
// /** default constructor */
// public UserInfo() {
// }
//
// /** full constructor */
// public UserInfo(Integer uid, String nickname, Integer level, Integer experience, String actions) {
// this.uid = uid;
// this.nickname = nickname;
// this.level = level;
// this.experience = experience;
// this.actions = actions;
// }
//
// @Id
// @Column(name = "uid", unique = true, nullable = false)
// public Integer getUid() {
// return this.uid;
// }
//
// public void setUid(Integer uid) {
// this.uid = uid;
// }
//
// @Column(name = "nickname", nullable = false, length = 30)
// public String getNickname() {
// return this.nickname;
// }
//
// public void setNickname(String nickname) {
// this.nickname = nickname;
// }
//
// @Column(name = "level", nullable = false)
// public Integer getLevel() {
// return this.level;
// }
//
// public void setLevel(Integer level) {
// this.level = level;
// }
//
// @Column(name = "experience", nullable = false)
// public Integer getExperience() {
// return this.experience;
// }
//
// public void setExperience(Integer experience) {
// this.experience = experience;
// }
//
// @Column(name = "actions", nullable = false, length = 65535)
// public String getActions() {
// return this.actions;
// }
//
// public void setActions(String actions) {
// this.actions = actions;
// }
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/sdm/service/UserInfoService.java
// public class UserInfoService extends BaseService {
//
// public final static String BEAN_ID = "userInfoService";
//
// @Autowired
// protected UserInfoDAO dao;
//
// @PostConstruct
// protected void setDao() {
// super.setDao(dao);
// }
//
// public IBaseModel findByUid(int uid) {
// IBaseModel model = RsyncManager.get(uid, UserInfoRsync.class);
// if (model == null) {
// model = super.findOneByProperty(UserInfoDAO.UID, uid);
// }
// return model;
// }
//
// public static String getDefaultActions() {
// Map<String, Integer> actions = new HashMap<>();
// actions.put(Integer.toString(AttackAction.ID), 1);
// return BaseJson.ObjectToJson(actions);
// }
//
// }
|
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.zhaidaosi.game.jgframework.common.sdm.IBaseModel;
import com.zhaidaosi.game.jgframework.common.spring.ServiceManager;
import com.zhaidaosi.game.jgframework.rsync.BaseRsync;
import com.zhaidaosi.game.server.sdm.model.UserInfo;
import com.zhaidaosi.game.server.sdm.service.UserInfoService;
|
package com.zhaidaosi.game.server.rsync;
public class UserInfoRsync extends BaseRsync {
private static final Logger log = LoggerFactory.getLogger(UserInfoRsync.class);
@Override
public void runRsync() {
|
// Path: src/main/java/com/zhaidaosi/game/server/sdm/model/UserInfo.java
// @SuppressWarnings("serial")
// @Entity
// @Table(name = "user_info", catalog = "jgframework", uniqueConstraints = @UniqueConstraint(columnNames = "uid"))
// public class UserInfo extends BaseModel {
//
// // Fields
//
// private Integer uid;
// private String nickname;
// private Integer level;
// private Integer experience;
// private String actions;
//
// // Constructors
//
// /** default constructor */
// public UserInfo() {
// }
//
// /** full constructor */
// public UserInfo(Integer uid, String nickname, Integer level, Integer experience, String actions) {
// this.uid = uid;
// this.nickname = nickname;
// this.level = level;
// this.experience = experience;
// this.actions = actions;
// }
//
// @Id
// @Column(name = "uid", unique = true, nullable = false)
// public Integer getUid() {
// return this.uid;
// }
//
// public void setUid(Integer uid) {
// this.uid = uid;
// }
//
// @Column(name = "nickname", nullable = false, length = 30)
// public String getNickname() {
// return this.nickname;
// }
//
// public void setNickname(String nickname) {
// this.nickname = nickname;
// }
//
// @Column(name = "level", nullable = false)
// public Integer getLevel() {
// return this.level;
// }
//
// public void setLevel(Integer level) {
// this.level = level;
// }
//
// @Column(name = "experience", nullable = false)
// public Integer getExperience() {
// return this.experience;
// }
//
// public void setExperience(Integer experience) {
// this.experience = experience;
// }
//
// @Column(name = "actions", nullable = false, length = 65535)
// public String getActions() {
// return this.actions;
// }
//
// public void setActions(String actions) {
// this.actions = actions;
// }
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/sdm/service/UserInfoService.java
// public class UserInfoService extends BaseService {
//
// public final static String BEAN_ID = "userInfoService";
//
// @Autowired
// protected UserInfoDAO dao;
//
// @PostConstruct
// protected void setDao() {
// super.setDao(dao);
// }
//
// public IBaseModel findByUid(int uid) {
// IBaseModel model = RsyncManager.get(uid, UserInfoRsync.class);
// if (model == null) {
// model = super.findOneByProperty(UserInfoDAO.UID, uid);
// }
// return model;
// }
//
// public static String getDefaultActions() {
// Map<String, Integer> actions = new HashMap<>();
// actions.put(Integer.toString(AttackAction.ID), 1);
// return BaseJson.ObjectToJson(actions);
// }
//
// }
// Path: src/main/java/com/zhaidaosi/game/server/rsync/UserInfoRsync.java
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.zhaidaosi.game.jgframework.common.sdm.IBaseModel;
import com.zhaidaosi.game.jgframework.common.spring.ServiceManager;
import com.zhaidaosi.game.jgframework.rsync.BaseRsync;
import com.zhaidaosi.game.server.sdm.model.UserInfo;
import com.zhaidaosi.game.server.sdm.service.UserInfoService;
package com.zhaidaosi.game.server.rsync;
public class UserInfoRsync extends BaseRsync {
private static final Logger log = LoggerFactory.getLogger(UserInfoRsync.class);
@Override
public void runRsync() {
|
UserInfoService service = (UserInfoService) ServiceManager.getService(UserInfoService.BEAN_ID);
|
bupt1987/JgWeb
|
src/main/java/com/zhaidaosi/game/server/rsync/UserInfoRsync.java
|
// Path: src/main/java/com/zhaidaosi/game/server/sdm/model/UserInfo.java
// @SuppressWarnings("serial")
// @Entity
// @Table(name = "user_info", catalog = "jgframework", uniqueConstraints = @UniqueConstraint(columnNames = "uid"))
// public class UserInfo extends BaseModel {
//
// // Fields
//
// private Integer uid;
// private String nickname;
// private Integer level;
// private Integer experience;
// private String actions;
//
// // Constructors
//
// /** default constructor */
// public UserInfo() {
// }
//
// /** full constructor */
// public UserInfo(Integer uid, String nickname, Integer level, Integer experience, String actions) {
// this.uid = uid;
// this.nickname = nickname;
// this.level = level;
// this.experience = experience;
// this.actions = actions;
// }
//
// @Id
// @Column(name = "uid", unique = true, nullable = false)
// public Integer getUid() {
// return this.uid;
// }
//
// public void setUid(Integer uid) {
// this.uid = uid;
// }
//
// @Column(name = "nickname", nullable = false, length = 30)
// public String getNickname() {
// return this.nickname;
// }
//
// public void setNickname(String nickname) {
// this.nickname = nickname;
// }
//
// @Column(name = "level", nullable = false)
// public Integer getLevel() {
// return this.level;
// }
//
// public void setLevel(Integer level) {
// this.level = level;
// }
//
// @Column(name = "experience", nullable = false)
// public Integer getExperience() {
// return this.experience;
// }
//
// public void setExperience(Integer experience) {
// this.experience = experience;
// }
//
// @Column(name = "actions", nullable = false, length = 65535)
// public String getActions() {
// return this.actions;
// }
//
// public void setActions(String actions) {
// this.actions = actions;
// }
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/sdm/service/UserInfoService.java
// public class UserInfoService extends BaseService {
//
// public final static String BEAN_ID = "userInfoService";
//
// @Autowired
// protected UserInfoDAO dao;
//
// @PostConstruct
// protected void setDao() {
// super.setDao(dao);
// }
//
// public IBaseModel findByUid(int uid) {
// IBaseModel model = RsyncManager.get(uid, UserInfoRsync.class);
// if (model == null) {
// model = super.findOneByProperty(UserInfoDAO.UID, uid);
// }
// return model;
// }
//
// public static String getDefaultActions() {
// Map<String, Integer> actions = new HashMap<>();
// actions.put(Integer.toString(AttackAction.ID), 1);
// return BaseJson.ObjectToJson(actions);
// }
//
// }
|
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.zhaidaosi.game.jgframework.common.sdm.IBaseModel;
import com.zhaidaosi.game.jgframework.common.spring.ServiceManager;
import com.zhaidaosi.game.jgframework.rsync.BaseRsync;
import com.zhaidaosi.game.server.sdm.model.UserInfo;
import com.zhaidaosi.game.server.sdm.service.UserInfoService;
|
package com.zhaidaosi.game.server.rsync;
public class UserInfoRsync extends BaseRsync {
private static final Logger log = LoggerFactory.getLogger(UserInfoRsync.class);
@Override
public void runRsync() {
UserInfoService service = (UserInfoService) ServiceManager.getService(UserInfoService.BEAN_ID);
for (Map.Entry<Integer, IBaseModel> entry : rsyncMap.entrySet()) {
|
// Path: src/main/java/com/zhaidaosi/game/server/sdm/model/UserInfo.java
// @SuppressWarnings("serial")
// @Entity
// @Table(name = "user_info", catalog = "jgframework", uniqueConstraints = @UniqueConstraint(columnNames = "uid"))
// public class UserInfo extends BaseModel {
//
// // Fields
//
// private Integer uid;
// private String nickname;
// private Integer level;
// private Integer experience;
// private String actions;
//
// // Constructors
//
// /** default constructor */
// public UserInfo() {
// }
//
// /** full constructor */
// public UserInfo(Integer uid, String nickname, Integer level, Integer experience, String actions) {
// this.uid = uid;
// this.nickname = nickname;
// this.level = level;
// this.experience = experience;
// this.actions = actions;
// }
//
// @Id
// @Column(name = "uid", unique = true, nullable = false)
// public Integer getUid() {
// return this.uid;
// }
//
// public void setUid(Integer uid) {
// this.uid = uid;
// }
//
// @Column(name = "nickname", nullable = false, length = 30)
// public String getNickname() {
// return this.nickname;
// }
//
// public void setNickname(String nickname) {
// this.nickname = nickname;
// }
//
// @Column(name = "level", nullable = false)
// public Integer getLevel() {
// return this.level;
// }
//
// public void setLevel(Integer level) {
// this.level = level;
// }
//
// @Column(name = "experience", nullable = false)
// public Integer getExperience() {
// return this.experience;
// }
//
// public void setExperience(Integer experience) {
// this.experience = experience;
// }
//
// @Column(name = "actions", nullable = false, length = 65535)
// public String getActions() {
// return this.actions;
// }
//
// public void setActions(String actions) {
// this.actions = actions;
// }
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/sdm/service/UserInfoService.java
// public class UserInfoService extends BaseService {
//
// public final static String BEAN_ID = "userInfoService";
//
// @Autowired
// protected UserInfoDAO dao;
//
// @PostConstruct
// protected void setDao() {
// super.setDao(dao);
// }
//
// public IBaseModel findByUid(int uid) {
// IBaseModel model = RsyncManager.get(uid, UserInfoRsync.class);
// if (model == null) {
// model = super.findOneByProperty(UserInfoDAO.UID, uid);
// }
// return model;
// }
//
// public static String getDefaultActions() {
// Map<String, Integer> actions = new HashMap<>();
// actions.put(Integer.toString(AttackAction.ID), 1);
// return BaseJson.ObjectToJson(actions);
// }
//
// }
// Path: src/main/java/com/zhaidaosi/game/server/rsync/UserInfoRsync.java
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.zhaidaosi.game.jgframework.common.sdm.IBaseModel;
import com.zhaidaosi.game.jgframework.common.spring.ServiceManager;
import com.zhaidaosi.game.jgframework.rsync.BaseRsync;
import com.zhaidaosi.game.server.sdm.model.UserInfo;
import com.zhaidaosi.game.server.sdm.service.UserInfoService;
package com.zhaidaosi.game.server.rsync;
public class UserInfoRsync extends BaseRsync {
private static final Logger log = LoggerFactory.getLogger(UserInfoRsync.class);
@Override
public void runRsync() {
UserInfoService service = (UserInfoService) ServiceManager.getService(UserInfoService.BEAN_ID);
for (Map.Entry<Integer, IBaseModel> entry : rsyncMap.entrySet()) {
|
UserInfo userInfo = (UserInfo) entry.getValue();
|
bupt1987/JgWeb
|
src/main/java/com/zhaidaosi/game/server/model/action/AttackAction.java
|
// Path: src/main/java/com/zhaidaosi/game/server/model/Duel.java
// public class Duel {
//
// public static final String END = "end";
// public static final String INIT = "init";
// public static final String MSG = "msg";
//
// public static Player doDuel(Player me, Player target, DuelZone zone, String handlerName) {
// Player hiter;
// Player beHiter;
// Player winer;
//
// zone.addPlayer(me);
// zone.addPlayer(target);
// BaseHandlerChannel ch = new BaseHandlerChannel(handlerName, zone.getChannelGroup());
//
// ch.writeGroup(Duel.write("", Duel.INIT, me, target));
//
// do {
// int select = getHiter();
// switch (select) {
// case 0:
// hiter = me;
// beHiter = target;
// break;
// case 1:
// hiter = target;
// beHiter = me;
// break;
// default:
// hiter = me;
// beHiter = target;
// break;
// }
// IBaseAction action = getAction(hiter);
// try {
// Thread.sleep(300);
// } catch (InterruptedException e) {
// }
// action.doAction(hiter, beHiter, ch);
// } while (me.getHp() > 0 && target.getHp() > 0);
//
// if (me.getHp() > 0) {
// winer = me;
// } else {
// winer = target;
// }
// ch.writeGroup(write(winer.getName() + " 获胜", END, me, target));
// zone.close();
// me.setHp(me.getTotalHp());
// target.setHp(target.getTotalHp());
//
// me.gOldPosition().getArea().addPlayer(me);
//
// target.gOldPosition().getArea().addPlayer(target);
//
// return winer;
// }
//
// public static OutMessage write(String msg, String action, Object me, Object target) {
// Map<String, Object> out = new HashMap<String, Object>();
// out.put("msg", msg);
// out.put("action", action);
// out.put("player_me", me);
// out.put("player_target", target);
// return OutMessage.showSucc(out);
// }
//
// private static int getHiter() {
// return new Random().nextInt(2);
// }
//
// private static IBaseAction getAction(BasePlayer hiter) {
// IBaseAction[] actions = new IBaseAction[hiter.getActions().size()];
// actions = hiter.getActions().values().toArray(actions);
// int select = 0;
// if (actions.length > 1) {
// int random = actions.length;
// select = new Random().nextInt(random);
// }
// return actions[select];
// }
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/model/player/Player.java
// public class Player extends BasePlayer {
//
// private static Map<Integer, Integer> levelExperience = new HashMap<>();
//
// private UserInfo userInfo;
// private BasePosition oldPosition;
// private Map<String, Integer> actionJson = new HashMap<>();
//
// static {
// levelExperience.put(1, 100);
// levelExperience.put(2, 300);
// levelExperience.put(3, 500);
// }
//
// @SuppressWarnings("unchecked")
// public void init(UserInfo userInfo) {
// this.userInfo = userInfo;
// this.name = userInfo.getNickname();
// this.level = userInfo.getLevel();
// this.totalHp = this.level * 100;
// this.hp = this.totalHp;
// this.experience = userInfo.getExperience();
//
// actionJson = BaseJson.JsonToObject(userInfo.getActions(), Map.class);
//
// for (Map.Entry<String, Integer> entry : actionJson.entrySet()) {
// AttackAction attackAction = (AttackAction) ActionManager.getAction(Integer.parseInt(entry.getKey()));
// attackAction.setLevel(entry.getValue());
// this.addAction(attackAction);
// }
//
// IBaseArea area = AreaManager.getArea(Area.ID);
// area.addPlayer(this);
// }
//
// public UserInfo getUserInfo() {
// return userInfo;
// }
//
// private void upLevel(int level) {
// if (this.level != level) {
// this.level = level;
// userInfo.setLevel(level);
// for (Entry<Integer, IBaseAction> entry : actions.entrySet()) {
// IBaseAction action = entry.getValue();
// if (action instanceof AttackAction) {
// ((AttackAction) action).setLevel(level);
// actionJson.put(Integer.toString(action.getId()), level);
// }
// userInfo.setActions(BaseJson.ObjectToJson(actionJson));
// }
// }
// }
//
// public void addExperience(int experience) {
// this.experience += experience;
// int _level = level;
// Integer _experience = levelExperience.get(_level);
// while (_experience != null && this.experience > _experience) {
// _level++;
// _experience = levelExperience.get(_level);
// }
// userInfo.setExperience(this.experience);
// upLevel(_level);
// RsyncManager.add(id, UserInfoRsync.class, userInfo);
// }
//
// public BasePosition gOldPosition() {
// return oldPosition;
// }
//
// public void sOldPosition(BasePosition oldPosition) {
// this.oldPosition = oldPosition;
// }
//
// }
|
import com.zhaidaosi.game.jgframework.handler.BaseHandlerChannel;
import com.zhaidaosi.game.jgframework.model.action.BaseAction;
import com.zhaidaosi.game.server.model.Duel;
import com.zhaidaosi.game.server.model.player.Player;
|
package com.zhaidaosi.game.server.model.action;
public class AttackAction extends BaseAction {
public static int ID = 1;
private int level = 1;
private int minDamage;
private int maxDamage;
public AttackAction() {
super(ID, "基本攻击");
}
@Override
public void doAction(Object self, Object target, BaseHandlerChannel ch) {
|
// Path: src/main/java/com/zhaidaosi/game/server/model/Duel.java
// public class Duel {
//
// public static final String END = "end";
// public static final String INIT = "init";
// public static final String MSG = "msg";
//
// public static Player doDuel(Player me, Player target, DuelZone zone, String handlerName) {
// Player hiter;
// Player beHiter;
// Player winer;
//
// zone.addPlayer(me);
// zone.addPlayer(target);
// BaseHandlerChannel ch = new BaseHandlerChannel(handlerName, zone.getChannelGroup());
//
// ch.writeGroup(Duel.write("", Duel.INIT, me, target));
//
// do {
// int select = getHiter();
// switch (select) {
// case 0:
// hiter = me;
// beHiter = target;
// break;
// case 1:
// hiter = target;
// beHiter = me;
// break;
// default:
// hiter = me;
// beHiter = target;
// break;
// }
// IBaseAction action = getAction(hiter);
// try {
// Thread.sleep(300);
// } catch (InterruptedException e) {
// }
// action.doAction(hiter, beHiter, ch);
// } while (me.getHp() > 0 && target.getHp() > 0);
//
// if (me.getHp() > 0) {
// winer = me;
// } else {
// winer = target;
// }
// ch.writeGroup(write(winer.getName() + " 获胜", END, me, target));
// zone.close();
// me.setHp(me.getTotalHp());
// target.setHp(target.getTotalHp());
//
// me.gOldPosition().getArea().addPlayer(me);
//
// target.gOldPosition().getArea().addPlayer(target);
//
// return winer;
// }
//
// public static OutMessage write(String msg, String action, Object me, Object target) {
// Map<String, Object> out = new HashMap<String, Object>();
// out.put("msg", msg);
// out.put("action", action);
// out.put("player_me", me);
// out.put("player_target", target);
// return OutMessage.showSucc(out);
// }
//
// private static int getHiter() {
// return new Random().nextInt(2);
// }
//
// private static IBaseAction getAction(BasePlayer hiter) {
// IBaseAction[] actions = new IBaseAction[hiter.getActions().size()];
// actions = hiter.getActions().values().toArray(actions);
// int select = 0;
// if (actions.length > 1) {
// int random = actions.length;
// select = new Random().nextInt(random);
// }
// return actions[select];
// }
//
// }
//
// Path: src/main/java/com/zhaidaosi/game/server/model/player/Player.java
// public class Player extends BasePlayer {
//
// private static Map<Integer, Integer> levelExperience = new HashMap<>();
//
// private UserInfo userInfo;
// private BasePosition oldPosition;
// private Map<String, Integer> actionJson = new HashMap<>();
//
// static {
// levelExperience.put(1, 100);
// levelExperience.put(2, 300);
// levelExperience.put(3, 500);
// }
//
// @SuppressWarnings("unchecked")
// public void init(UserInfo userInfo) {
// this.userInfo = userInfo;
// this.name = userInfo.getNickname();
// this.level = userInfo.getLevel();
// this.totalHp = this.level * 100;
// this.hp = this.totalHp;
// this.experience = userInfo.getExperience();
//
// actionJson = BaseJson.JsonToObject(userInfo.getActions(), Map.class);
//
// for (Map.Entry<String, Integer> entry : actionJson.entrySet()) {
// AttackAction attackAction = (AttackAction) ActionManager.getAction(Integer.parseInt(entry.getKey()));
// attackAction.setLevel(entry.getValue());
// this.addAction(attackAction);
// }
//
// IBaseArea area = AreaManager.getArea(Area.ID);
// area.addPlayer(this);
// }
//
// public UserInfo getUserInfo() {
// return userInfo;
// }
//
// private void upLevel(int level) {
// if (this.level != level) {
// this.level = level;
// userInfo.setLevel(level);
// for (Entry<Integer, IBaseAction> entry : actions.entrySet()) {
// IBaseAction action = entry.getValue();
// if (action instanceof AttackAction) {
// ((AttackAction) action).setLevel(level);
// actionJson.put(Integer.toString(action.getId()), level);
// }
// userInfo.setActions(BaseJson.ObjectToJson(actionJson));
// }
// }
// }
//
// public void addExperience(int experience) {
// this.experience += experience;
// int _level = level;
// Integer _experience = levelExperience.get(_level);
// while (_experience != null && this.experience > _experience) {
// _level++;
// _experience = levelExperience.get(_level);
// }
// userInfo.setExperience(this.experience);
// upLevel(_level);
// RsyncManager.add(id, UserInfoRsync.class, userInfo);
// }
//
// public BasePosition gOldPosition() {
// return oldPosition;
// }
//
// public void sOldPosition(BasePosition oldPosition) {
// this.oldPosition = oldPosition;
// }
//
// }
// Path: src/main/java/com/zhaidaosi/game/server/model/action/AttackAction.java
import com.zhaidaosi.game.jgframework.handler.BaseHandlerChannel;
import com.zhaidaosi.game.jgframework.model.action.BaseAction;
import com.zhaidaosi.game.server.model.Duel;
import com.zhaidaosi.game.server.model.player.Player;
package com.zhaidaosi.game.server.model.action;
public class AttackAction extends BaseAction {
public static int ID = 1;
private int level = 1;
private int minDamage;
private int maxDamage;
public AttackAction() {
super(ID, "基本攻击");
}
@Override
public void doAction(Object self, Object target, BaseHandlerChannel ch) {
|
Player selfPlayer = (Player) self;
|
bupt1987/JgWeb
|
src/test/java/client/TestJson.java
|
// Path: src/main/java/com/zhaidaosi/game/server/sdm/model/User.java
// @SuppressWarnings("serial")
// @Entity
// @Table(name = "user", catalog = "jgframework")
// public class User extends BaseModel {
//
// // Fields
//
// private Integer id;
// private String username;
// private String password;
// private Long lastLoginTime;
// private Long creatTime;
//
// // Constructors
//
// /** default constructor */
// public User() {
// }
//
// /** full constructor */
// public User(String username, String password, Long lastLoginTime, Long creatTime) {
// this.username = username;
// this.password = password;
// this.lastLoginTime = lastLoginTime;
// this.creatTime = creatTime;
// }
//
// // Property accessors
// @Id
// @GeneratedValue(strategy = IDENTITY)
// @Column(name = "id", unique = true, nullable = false)
// public Integer getId() {
// return this.id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// @Column(name = "username", nullable = false, length = 30)
// public String getUsername() {
// return this.username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// @Column(name = "password", nullable = false, length = 50)
// public String getPassword() {
// return this.password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// @Column(name = "last_login_time", nullable = false)
// public Long getLastLoginTime() {
// return this.lastLoginTime;
// }
//
// public void setLastLoginTime(Long lastLoginTime) {
// this.lastLoginTime = lastLoginTime;
// }
//
// @Column(name = "creat_time", nullable = false)
// public Long getCreatTime() {
// return this.creatTime;
// }
//
// public void setCreatTime(Long creatTime) {
// this.creatTime = creatTime;
// }
//
// }
|
import com.zhaidaosi.game.server.sdm.model.User;
|
package client;
public class TestJson {
public static void main(String[] args) {
|
// Path: src/main/java/com/zhaidaosi/game/server/sdm/model/User.java
// @SuppressWarnings("serial")
// @Entity
// @Table(name = "user", catalog = "jgframework")
// public class User extends BaseModel {
//
// // Fields
//
// private Integer id;
// private String username;
// private String password;
// private Long lastLoginTime;
// private Long creatTime;
//
// // Constructors
//
// /** default constructor */
// public User() {
// }
//
// /** full constructor */
// public User(String username, String password, Long lastLoginTime, Long creatTime) {
// this.username = username;
// this.password = password;
// this.lastLoginTime = lastLoginTime;
// this.creatTime = creatTime;
// }
//
// // Property accessors
// @Id
// @GeneratedValue(strategy = IDENTITY)
// @Column(name = "id", unique = true, nullable = false)
// public Integer getId() {
// return this.id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// @Column(name = "username", nullable = false, length = 30)
// public String getUsername() {
// return this.username;
// }
//
// public void setUsername(String username) {
// this.username = username;
// }
//
// @Column(name = "password", nullable = false, length = 50)
// public String getPassword() {
// return this.password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// @Column(name = "last_login_time", nullable = false)
// public Long getLastLoginTime() {
// return this.lastLoginTime;
// }
//
// public void setLastLoginTime(Long lastLoginTime) {
// this.lastLoginTime = lastLoginTime;
// }
//
// @Column(name = "creat_time", nullable = false)
// public Long getCreatTime() {
// return this.creatTime;
// }
//
// public void setCreatTime(Long creatTime) {
// this.creatTime = creatTime;
// }
//
// }
// Path: src/test/java/client/TestJson.java
import com.zhaidaosi.game.server.sdm.model.User;
package client;
public class TestJson {
public static void main(String[] args) {
|
User user = new User("test", "123456", 1L, 1L);
|
jaksab/EasyNetwork
|
easynet/src/main/java/pro/oncreate/easynet/methods/Method.java
|
// Path: easynet/src/main/java/pro/oncreate/easynet/data/NConst.java
// @SuppressWarnings("unused,WeakerAccess")
// public class NConst {
//
// //
// //
// //
//
// public static final String POST = "POST";
// public static final String GET = "GET";
// public static final String PUT = "PUT";
// public static final String DELETE = "DELETE";
// public static final String OPTIONS = "OPTIONS";
// public static final String HEAD = "HEAD";
// public static final String PATCH = "PATCH";
//
//
// //
// // Headers
// //
//
// public static final String CONTENT_TYPE = "Content-Type";
// public static final String ACCEPT_TYPE = "Accept";
// public static final String CONTENT_LANGUAGE = "Content-Language";
// public static final String ACCEPT_LANGUAGE = "Accept-Language";
// public static final String ACCEPT_CHARSET = "Accept-Charset";
// public static final String ACCEPT_ENCODING = "Accept-Encoding";
// public static final String CACHE_CONTROL = "Cache-Control";
// public static final String CONNECTION = "Connection";
// public static final String COOKIE = "Cookie";
// public static final String USER_AGENT = "User-Agent";
// public static final String DATE = "Date";
// public static final String ACCEPT_DATETIME = "Accept-Datetime";
//
// // Default values
// //
//
// // MIME TYPES
// public static final String MIME_TYPE_X_WWW_FORM_URLENCODED = "application/x-www-form-urlencoded";
// public static final String MIME_TYPE_JSON = "application/json";
// public static final String MIME_TYPE_GZIP = "application/gzip";
// public static final String MIME_TYPE_ZIP = "application/zip";
// public static final String MIME_TYPE_MULTIPART_FORM_DATA = "multipart/form-data";
// public static final String MIME_TYPE_IMAGE_JPEG = "image/jpeg";
// public static final String MIME_TYPE_IMAGE_PNG = "image/png";
// public static final String MIME_TYPE_IMAGE_GIF = "image/gif";
// public static final String MIME_TYPE_TEXT_HTML = "text/html";
// public static final String MIME_TYPE_TEXT_PLAIN = "text/plain";
// public static final String MIME_TYPE_TEXT_XML = " text/xml";
// public static final String MIME_TYPE_TEST = " test";
//
// // ACCEPT ENCODING
// public static final String ACCEPT_ENCODING_COMPRESS = "compress";
// public static final String ACCEPT_ENCODING_GZIP = "gzip";
// public static final String ACCEPT_ENCODING_DEFLATE = "deflate";
// public static final String ACCEPT_ENCODING_SDCH = "sdch";
// public static final String ACCEPT_ENCODING_IDENTITY = "identity";
// }
|
import android.support.annotation.NonNull;
import pro.oncreate.easynet.data.NConst;
|
package pro.oncreate.easynet.methods;
/**
* Created by Andrii Konovalenko, 2014-2017 years.
* Copyright © 2017 [Andrii Konovalenko]. All Rights Reserved.
*/
@SuppressWarnings("unused,WeakerAccess")
public abstract class Method {
public abstract String name();
public abstract boolean withBody();
public static Method getMethodByName(String name) {
Method method = GET;
switch (name) {
|
// Path: easynet/src/main/java/pro/oncreate/easynet/data/NConst.java
// @SuppressWarnings("unused,WeakerAccess")
// public class NConst {
//
// //
// //
// //
//
// public static final String POST = "POST";
// public static final String GET = "GET";
// public static final String PUT = "PUT";
// public static final String DELETE = "DELETE";
// public static final String OPTIONS = "OPTIONS";
// public static final String HEAD = "HEAD";
// public static final String PATCH = "PATCH";
//
//
// //
// // Headers
// //
//
// public static final String CONTENT_TYPE = "Content-Type";
// public static final String ACCEPT_TYPE = "Accept";
// public static final String CONTENT_LANGUAGE = "Content-Language";
// public static final String ACCEPT_LANGUAGE = "Accept-Language";
// public static final String ACCEPT_CHARSET = "Accept-Charset";
// public static final String ACCEPT_ENCODING = "Accept-Encoding";
// public static final String CACHE_CONTROL = "Cache-Control";
// public static final String CONNECTION = "Connection";
// public static final String COOKIE = "Cookie";
// public static final String USER_AGENT = "User-Agent";
// public static final String DATE = "Date";
// public static final String ACCEPT_DATETIME = "Accept-Datetime";
//
// // Default values
// //
//
// // MIME TYPES
// public static final String MIME_TYPE_X_WWW_FORM_URLENCODED = "application/x-www-form-urlencoded";
// public static final String MIME_TYPE_JSON = "application/json";
// public static final String MIME_TYPE_GZIP = "application/gzip";
// public static final String MIME_TYPE_ZIP = "application/zip";
// public static final String MIME_TYPE_MULTIPART_FORM_DATA = "multipart/form-data";
// public static final String MIME_TYPE_IMAGE_JPEG = "image/jpeg";
// public static final String MIME_TYPE_IMAGE_PNG = "image/png";
// public static final String MIME_TYPE_IMAGE_GIF = "image/gif";
// public static final String MIME_TYPE_TEXT_HTML = "text/html";
// public static final String MIME_TYPE_TEXT_PLAIN = "text/plain";
// public static final String MIME_TYPE_TEXT_XML = " text/xml";
// public static final String MIME_TYPE_TEST = " test";
//
// // ACCEPT ENCODING
// public static final String ACCEPT_ENCODING_COMPRESS = "compress";
// public static final String ACCEPT_ENCODING_GZIP = "gzip";
// public static final String ACCEPT_ENCODING_DEFLATE = "deflate";
// public static final String ACCEPT_ENCODING_SDCH = "sdch";
// public static final String ACCEPT_ENCODING_IDENTITY = "identity";
// }
// Path: easynet/src/main/java/pro/oncreate/easynet/methods/Method.java
import android.support.annotation.NonNull;
import pro.oncreate.easynet.data.NConst;
package pro.oncreate.easynet.methods;
/**
* Created by Andrii Konovalenko, 2014-2017 years.
* Copyright © 2017 [Andrii Konovalenko]. All Rights Reserved.
*/
@SuppressWarnings("unused,WeakerAccess")
public abstract class Method {
public abstract String name();
public abstract boolean withBody();
public static Method getMethodByName(String name) {
Method method = GET;
switch (name) {
|
case NConst.GET:
|
jaksab/EasyNetwork
|
easynet/src/main/java/pro/oncreate/easynet/utils/NDataBuilder.java
|
// Path: easynet/src/main/java/pro/oncreate/easynet/models/subsidiary/NKeyValueModel.java
// @SuppressWarnings("unused,WeakerAccess")
// public class NKeyValueModel extends NKeyModel {
//
// private String value;
//
// public NKeyValueModel(String key, String value) {
// super(key);
// this.value = value;
// }
//
// public String getValue() {
// return value;
// }
//
// public void setValue(String value) {
// this.value = value;
// }
// }
|
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;
import pro.oncreate.easynet.models.subsidiary.NKeyValueModel;
|
package pro.oncreate.easynet.utils;
/**
* Copyright (c) $today.year. Konovalenko Andrii [[email protected]]
*/
@SuppressWarnings("unused,WeakerAccess")
public class NDataBuilder {
|
// Path: easynet/src/main/java/pro/oncreate/easynet/models/subsidiary/NKeyValueModel.java
// @SuppressWarnings("unused,WeakerAccess")
// public class NKeyValueModel extends NKeyModel {
//
// private String value;
//
// public NKeyValueModel(String key, String value) {
// super(key);
// this.value = value;
// }
//
// public String getValue() {
// return value;
// }
//
// public void setValue(String value) {
// this.value = value;
// }
// }
// Path: easynet/src/main/java/pro/oncreate/easynet/utils/NDataBuilder.java
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;
import pro.oncreate.easynet.models.subsidiary.NKeyValueModel;
package pro.oncreate.easynet.utils;
/**
* Copyright (c) $today.year. Konovalenko Andrii [[email protected]]
*/
@SuppressWarnings("unused,WeakerAccess")
public class NDataBuilder {
|
public static String getQuery(List<NKeyValueModel> params, String charset) throws UnsupportedEncodingException {
|
jaksab/EasyNetwork
|
app/src/main/java/pro/oncreate/easynetwork/models/CountryModel.java
|
// Path: easynet/src/main/java/pro/oncreate/easynet/models/NBaseModel.java
// @SuppressWarnings("unused,WeakerAccess")
// public abstract class NBaseModel {
//
// public abstract NBaseModel parse(NResponseModel responseModel, JSONObject jsonObject);
// }
//
// Path: easynet/src/main/java/pro/oncreate/easynet/models/NResponseModel.java
// @SuppressWarnings("unused,WeakerAccess")
// public class NResponseModel {
//
// public static final int STATUS_TYPE_SUCCESS = 1, STATUS_TYPE_ERROR = 2;
//
// private String url;
// private int statusCode;
// private String body;
// private Map<String, List<String>> headers;
// private long endTime;
// private int responseTime;
// private boolean redirectInterrupted;
// private String redirectLocation;
// private boolean fromCache;
// private NRequestModel requestModel;
//
// public NResponseModel(String url, int statusCode, String body, Map<String, List<String>> headers) {
// this.url = url;
// this.statusCode = statusCode;
// this.body = body;
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public int getStatusCode() {
// return statusCode;
// }
//
// public void setStatusCode(int statusCode) {
// this.statusCode = statusCode;
// }
//
// public String getBody() {
// return body;
// }
//
// public void setBody(String body) {
// this.body = body;
// }
//
// public Map<String, List<String>> getHeaders() {
// return headers;
// }
//
// public void setHeaders(Map<String, List<String>> headers) {
// this.headers = headers;
// }
//
// public int getResponseTime() {
// return responseTime;
// }
//
// public void setResponseTime(int responseTime) {
// this.responseTime = responseTime;
// }
//
// public long getEndTime() {
// return endTime;
// }
//
// public void setEndTime(long time) {
// this.endTime = time;
// }
//
// public int statusType() {
// return statusCode / 100 == 2 ? STATUS_TYPE_SUCCESS : STATUS_TYPE_ERROR;
// }
//
// public boolean isRedirectInterrupted() {
// return redirectInterrupted;
// }
//
// public void setRedirectInterrupted(boolean redirectInterrupted) {
// this.redirectInterrupted = redirectInterrupted;
// }
//
// public String getRedirectLocation() {
// return redirectLocation;
// }
//
// public void setRedirectLocation(String redirectLocation) {
// this.redirectLocation = redirectLocation;
// }
//
// public boolean isFromCache() {
// return fromCache;
// }
//
// public void setFromCache(boolean fromCache) {
// this.fromCache = fromCache;
// }
//
// public NRequestModel getRequestModel() {
// return requestModel;
// }
//
// public void setRequestModel(NRequestModel requestModel) {
// this.requestModel = requestModel;
// }
// }
|
import org.json.JSONObject;
import pro.oncreate.easynet.models.NBaseModel;
import pro.oncreate.easynet.models.NResponseModel;
|
this.id = id;
this.code = code;
this.name = name;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
|
// Path: easynet/src/main/java/pro/oncreate/easynet/models/NBaseModel.java
// @SuppressWarnings("unused,WeakerAccess")
// public abstract class NBaseModel {
//
// public abstract NBaseModel parse(NResponseModel responseModel, JSONObject jsonObject);
// }
//
// Path: easynet/src/main/java/pro/oncreate/easynet/models/NResponseModel.java
// @SuppressWarnings("unused,WeakerAccess")
// public class NResponseModel {
//
// public static final int STATUS_TYPE_SUCCESS = 1, STATUS_TYPE_ERROR = 2;
//
// private String url;
// private int statusCode;
// private String body;
// private Map<String, List<String>> headers;
// private long endTime;
// private int responseTime;
// private boolean redirectInterrupted;
// private String redirectLocation;
// private boolean fromCache;
// private NRequestModel requestModel;
//
// public NResponseModel(String url, int statusCode, String body, Map<String, List<String>> headers) {
// this.url = url;
// this.statusCode = statusCode;
// this.body = body;
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public int getStatusCode() {
// return statusCode;
// }
//
// public void setStatusCode(int statusCode) {
// this.statusCode = statusCode;
// }
//
// public String getBody() {
// return body;
// }
//
// public void setBody(String body) {
// this.body = body;
// }
//
// public Map<String, List<String>> getHeaders() {
// return headers;
// }
//
// public void setHeaders(Map<String, List<String>> headers) {
// this.headers = headers;
// }
//
// public int getResponseTime() {
// return responseTime;
// }
//
// public void setResponseTime(int responseTime) {
// this.responseTime = responseTime;
// }
//
// public long getEndTime() {
// return endTime;
// }
//
// public void setEndTime(long time) {
// this.endTime = time;
// }
//
// public int statusType() {
// return statusCode / 100 == 2 ? STATUS_TYPE_SUCCESS : STATUS_TYPE_ERROR;
// }
//
// public boolean isRedirectInterrupted() {
// return redirectInterrupted;
// }
//
// public void setRedirectInterrupted(boolean redirectInterrupted) {
// this.redirectInterrupted = redirectInterrupted;
// }
//
// public String getRedirectLocation() {
// return redirectLocation;
// }
//
// public void setRedirectLocation(String redirectLocation) {
// this.redirectLocation = redirectLocation;
// }
//
// public boolean isFromCache() {
// return fromCache;
// }
//
// public void setFromCache(boolean fromCache) {
// this.fromCache = fromCache;
// }
//
// public NRequestModel getRequestModel() {
// return requestModel;
// }
//
// public void setRequestModel(NRequestModel requestModel) {
// this.requestModel = requestModel;
// }
// }
// Path: app/src/main/java/pro/oncreate/easynetwork/models/CountryModel.java
import org.json.JSONObject;
import pro.oncreate.easynet.models.NBaseModel;
import pro.oncreate.easynet.models.NResponseModel;
this.id = id;
this.code = code;
this.name = name;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
|
public CountryModel parse(NResponseModel responseModel, JSONObject jsonObject) {
|
jaksab/EasyNetwork
|
easynet/src/main/java/pro/oncreate/easynet/utils/NHelper.java
|
// Path: easynet/src/main/java/pro/oncreate/easynet/models/NResponseModel.java
// @SuppressWarnings("unused,WeakerAccess")
// public class NResponseModel {
//
// public static final int STATUS_TYPE_SUCCESS = 1, STATUS_TYPE_ERROR = 2;
//
// private String url;
// private int statusCode;
// private String body;
// private Map<String, List<String>> headers;
// private long endTime;
// private int responseTime;
// private boolean redirectInterrupted;
// private String redirectLocation;
// private boolean fromCache;
// private NRequestModel requestModel;
//
// public NResponseModel(String url, int statusCode, String body, Map<String, List<String>> headers) {
// this.url = url;
// this.statusCode = statusCode;
// this.body = body;
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public int getStatusCode() {
// return statusCode;
// }
//
// public void setStatusCode(int statusCode) {
// this.statusCode = statusCode;
// }
//
// public String getBody() {
// return body;
// }
//
// public void setBody(String body) {
// this.body = body;
// }
//
// public Map<String, List<String>> getHeaders() {
// return headers;
// }
//
// public void setHeaders(Map<String, List<String>> headers) {
// this.headers = headers;
// }
//
// public int getResponseTime() {
// return responseTime;
// }
//
// public void setResponseTime(int responseTime) {
// this.responseTime = responseTime;
// }
//
// public long getEndTime() {
// return endTime;
// }
//
// public void setEndTime(long time) {
// this.endTime = time;
// }
//
// public int statusType() {
// return statusCode / 100 == 2 ? STATUS_TYPE_SUCCESS : STATUS_TYPE_ERROR;
// }
//
// public boolean isRedirectInterrupted() {
// return redirectInterrupted;
// }
//
// public void setRedirectInterrupted(boolean redirectInterrupted) {
// this.redirectInterrupted = redirectInterrupted;
// }
//
// public String getRedirectLocation() {
// return redirectLocation;
// }
//
// public void setRedirectLocation(String redirectLocation) {
// this.redirectLocation = redirectLocation;
// }
//
// public boolean isFromCache() {
// return fromCache;
// }
//
// public void setFromCache(boolean fromCache) {
// this.fromCache = fromCache;
// }
//
// public NRequestModel getRequestModel() {
// return requestModel;
// }
//
// public void setRequestModel(NRequestModel requestModel) {
// this.requestModel = requestModel;
// }
// }
|
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import java.util.List;
import pro.oncreate.easynet.models.NResponseModel;
|
package pro.oncreate.easynet.utils;
/**
* Created by andrej on 17.11.15.
*/
@SuppressWarnings("unused,WeakerAccess")
public class NHelper {
static public boolean isActiveInternet(Context context) {
try {
ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo nInfo = cm.getActiveNetworkInfo();
return !(nInfo == null || !nInfo.isConnected());
} catch (Exception e) {
return false;
}
}
|
// Path: easynet/src/main/java/pro/oncreate/easynet/models/NResponseModel.java
// @SuppressWarnings("unused,WeakerAccess")
// public class NResponseModel {
//
// public static final int STATUS_TYPE_SUCCESS = 1, STATUS_TYPE_ERROR = 2;
//
// private String url;
// private int statusCode;
// private String body;
// private Map<String, List<String>> headers;
// private long endTime;
// private int responseTime;
// private boolean redirectInterrupted;
// private String redirectLocation;
// private boolean fromCache;
// private NRequestModel requestModel;
//
// public NResponseModel(String url, int statusCode, String body, Map<String, List<String>> headers) {
// this.url = url;
// this.statusCode = statusCode;
// this.body = body;
// this.headers = headers;
// }
//
// public String getUrl() {
// return url;
// }
//
// public void setUrl(String url) {
// this.url = url;
// }
//
// public int getStatusCode() {
// return statusCode;
// }
//
// public void setStatusCode(int statusCode) {
// this.statusCode = statusCode;
// }
//
// public String getBody() {
// return body;
// }
//
// public void setBody(String body) {
// this.body = body;
// }
//
// public Map<String, List<String>> getHeaders() {
// return headers;
// }
//
// public void setHeaders(Map<String, List<String>> headers) {
// this.headers = headers;
// }
//
// public int getResponseTime() {
// return responseTime;
// }
//
// public void setResponseTime(int responseTime) {
// this.responseTime = responseTime;
// }
//
// public long getEndTime() {
// return endTime;
// }
//
// public void setEndTime(long time) {
// this.endTime = time;
// }
//
// public int statusType() {
// return statusCode / 100 == 2 ? STATUS_TYPE_SUCCESS : STATUS_TYPE_ERROR;
// }
//
// public boolean isRedirectInterrupted() {
// return redirectInterrupted;
// }
//
// public void setRedirectInterrupted(boolean redirectInterrupted) {
// this.redirectInterrupted = redirectInterrupted;
// }
//
// public String getRedirectLocation() {
// return redirectLocation;
// }
//
// public void setRedirectLocation(String redirectLocation) {
// this.redirectLocation = redirectLocation;
// }
//
// public boolean isFromCache() {
// return fromCache;
// }
//
// public void setFromCache(boolean fromCache) {
// this.fromCache = fromCache;
// }
//
// public NRequestModel getRequestModel() {
// return requestModel;
// }
//
// public void setRequestModel(NRequestModel requestModel) {
// this.requestModel = requestModel;
// }
// }
// Path: easynet/src/main/java/pro/oncreate/easynet/utils/NHelper.java
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import java.util.List;
import pro.oncreate.easynet.models.NResponseModel;
package pro.oncreate.easynet.utils;
/**
* Created by andrej on 17.11.15.
*/
@SuppressWarnings("unused,WeakerAccess")
public class NHelper {
static public boolean isActiveInternet(Context context) {
try {
ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo nInfo = cm.getActiveNetworkInfo();
return !(nInfo == null || !nInfo.isConnected());
} catch (Exception e) {
return false;
}
}
|
static public String getFirstHeader(NResponseModel responseModel, String header) {
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/dependencies/modules/ApplicationModule.java
|
// Path: app/src/main/java/com/pacoworks/dereference/DereferenceApplication.java
// public class DereferenceApplication extends Application {
// @Inject
// MainInitialiser mainInitialiser;
//
// @Inject
// FlavourInitialiser flavourInitialiser;
// private ApplicationInjectionComponent component;
//
// public static DereferenceApplication get(Context context) {
// return (DereferenceApplication)context.getApplicationContext();
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// buildComponentAndInject();
// }
//
// private void buildComponentAndInject() {
// component = ApplicationInjectionComponent.Initializer.init(this);
// /* Force initialisers to be created */
// component.inject(this);
// }
//
// public ApplicationInjectionComponent component() {
// return component;
// }
// }
//
// Path: app/src/whatever/java/com/pacoworks/dereference/FlavourInitialiser.java
// public class FlavourInitialiser {
// public FlavourInitialiser(DereferenceApplication application) {
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/MainInitialiser.java
// public class MainInitialiser {
// private final Application.ActivityLifecycleCallbacks initialiserCallbacks = new Application.ActivityLifecycleCallbacks() {
// @Override
// public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
// }
//
// @Override
// public void onActivityStarted(Activity activity) {
// }
//
// @Override
// public void onActivityResumed(Activity activity) {
// }
//
// @Override
// public void onActivityPaused(Activity activity) {
// }
//
// @Override
// public void onActivityStopped(Activity activity) {
// }
//
// @Override
// public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
// }
//
// @Override
// public void onActivityDestroyed(Activity activity) {
// }
// };
//
// public MainInitialiser(DereferenceApplication application, OkHttpClient okHttpClient) {
// application.registerActivityLifecycleCallbacks(initialiserCallbacks);
// LeakCanary.install(application);
// if (BuildConfig.DEBUG) {
// // FIXME no stetho for now
// // Stetho.initialize(Stetho.newInitializerBuilder(application)
// // .enableDumpapp(Stetho.defaultDumperPluginsProvider(application)).build());
// LumberYard lumberYard = LumberYard.getInstance(application);
// lumberYard.cleanUp();
// Timber.plant(lumberYard.tree());
// Timber.plant(new Timber.DebugTree());
// }
// }
// }
|
import javax.inject.Singleton;
import android.content.Context;
import com.pacoworks.dereference.DereferenceApplication;
import com.pacoworks.dereference.FlavourInitialiser;
import com.pacoworks.dereference.MainInitialiser;
import com.squareup.okhttp.OkHttpClient;
import dagger.Module;
import dagger.Provides;
|
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.dependencies.modules;
@Module
public class ApplicationModule {
|
// Path: app/src/main/java/com/pacoworks/dereference/DereferenceApplication.java
// public class DereferenceApplication extends Application {
// @Inject
// MainInitialiser mainInitialiser;
//
// @Inject
// FlavourInitialiser flavourInitialiser;
// private ApplicationInjectionComponent component;
//
// public static DereferenceApplication get(Context context) {
// return (DereferenceApplication)context.getApplicationContext();
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// buildComponentAndInject();
// }
//
// private void buildComponentAndInject() {
// component = ApplicationInjectionComponent.Initializer.init(this);
// /* Force initialisers to be created */
// component.inject(this);
// }
//
// public ApplicationInjectionComponent component() {
// return component;
// }
// }
//
// Path: app/src/whatever/java/com/pacoworks/dereference/FlavourInitialiser.java
// public class FlavourInitialiser {
// public FlavourInitialiser(DereferenceApplication application) {
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/MainInitialiser.java
// public class MainInitialiser {
// private final Application.ActivityLifecycleCallbacks initialiserCallbacks = new Application.ActivityLifecycleCallbacks() {
// @Override
// public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
// }
//
// @Override
// public void onActivityStarted(Activity activity) {
// }
//
// @Override
// public void onActivityResumed(Activity activity) {
// }
//
// @Override
// public void onActivityPaused(Activity activity) {
// }
//
// @Override
// public void onActivityStopped(Activity activity) {
// }
//
// @Override
// public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
// }
//
// @Override
// public void onActivityDestroyed(Activity activity) {
// }
// };
//
// public MainInitialiser(DereferenceApplication application, OkHttpClient okHttpClient) {
// application.registerActivityLifecycleCallbacks(initialiserCallbacks);
// LeakCanary.install(application);
// if (BuildConfig.DEBUG) {
// // FIXME no stetho for now
// // Stetho.initialize(Stetho.newInitializerBuilder(application)
// // .enableDumpapp(Stetho.defaultDumperPluginsProvider(application)).build());
// LumberYard lumberYard = LumberYard.getInstance(application);
// lumberYard.cleanUp();
// Timber.plant(lumberYard.tree());
// Timber.plant(new Timber.DebugTree());
// }
// }
// }
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/modules/ApplicationModule.java
import javax.inject.Singleton;
import android.content.Context;
import com.pacoworks.dereference.DereferenceApplication;
import com.pacoworks.dereference.FlavourInitialiser;
import com.pacoworks.dereference.MainInitialiser;
import com.squareup.okhttp.OkHttpClient;
import dagger.Module;
import dagger.Provides;
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.dependencies.modules;
@Module
public class ApplicationModule {
|
DereferenceApplication application;
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/dependencies/modules/ApplicationModule.java
|
// Path: app/src/main/java/com/pacoworks/dereference/DereferenceApplication.java
// public class DereferenceApplication extends Application {
// @Inject
// MainInitialiser mainInitialiser;
//
// @Inject
// FlavourInitialiser flavourInitialiser;
// private ApplicationInjectionComponent component;
//
// public static DereferenceApplication get(Context context) {
// return (DereferenceApplication)context.getApplicationContext();
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// buildComponentAndInject();
// }
//
// private void buildComponentAndInject() {
// component = ApplicationInjectionComponent.Initializer.init(this);
// /* Force initialisers to be created */
// component.inject(this);
// }
//
// public ApplicationInjectionComponent component() {
// return component;
// }
// }
//
// Path: app/src/whatever/java/com/pacoworks/dereference/FlavourInitialiser.java
// public class FlavourInitialiser {
// public FlavourInitialiser(DereferenceApplication application) {
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/MainInitialiser.java
// public class MainInitialiser {
// private final Application.ActivityLifecycleCallbacks initialiserCallbacks = new Application.ActivityLifecycleCallbacks() {
// @Override
// public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
// }
//
// @Override
// public void onActivityStarted(Activity activity) {
// }
//
// @Override
// public void onActivityResumed(Activity activity) {
// }
//
// @Override
// public void onActivityPaused(Activity activity) {
// }
//
// @Override
// public void onActivityStopped(Activity activity) {
// }
//
// @Override
// public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
// }
//
// @Override
// public void onActivityDestroyed(Activity activity) {
// }
// };
//
// public MainInitialiser(DereferenceApplication application, OkHttpClient okHttpClient) {
// application.registerActivityLifecycleCallbacks(initialiserCallbacks);
// LeakCanary.install(application);
// if (BuildConfig.DEBUG) {
// // FIXME no stetho for now
// // Stetho.initialize(Stetho.newInitializerBuilder(application)
// // .enableDumpapp(Stetho.defaultDumperPluginsProvider(application)).build());
// LumberYard lumberYard = LumberYard.getInstance(application);
// lumberYard.cleanUp();
// Timber.plant(lumberYard.tree());
// Timber.plant(new Timber.DebugTree());
// }
// }
// }
|
import javax.inject.Singleton;
import android.content.Context;
import com.pacoworks.dereference.DereferenceApplication;
import com.pacoworks.dereference.FlavourInitialiser;
import com.pacoworks.dereference.MainInitialiser;
import com.squareup.okhttp.OkHttpClient;
import dagger.Module;
import dagger.Provides;
|
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.dependencies.modules;
@Module
public class ApplicationModule {
DereferenceApplication application;
public ApplicationModule(DereferenceApplication app) {
application = app;
}
@Provides
@Singleton
DereferenceApplication provideApplication() {
return application;
}
@Provides
@Singleton
Context provideContext() {
return application;
}
@Provides
@Singleton
|
// Path: app/src/main/java/com/pacoworks/dereference/DereferenceApplication.java
// public class DereferenceApplication extends Application {
// @Inject
// MainInitialiser mainInitialiser;
//
// @Inject
// FlavourInitialiser flavourInitialiser;
// private ApplicationInjectionComponent component;
//
// public static DereferenceApplication get(Context context) {
// return (DereferenceApplication)context.getApplicationContext();
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// buildComponentAndInject();
// }
//
// private void buildComponentAndInject() {
// component = ApplicationInjectionComponent.Initializer.init(this);
// /* Force initialisers to be created */
// component.inject(this);
// }
//
// public ApplicationInjectionComponent component() {
// return component;
// }
// }
//
// Path: app/src/whatever/java/com/pacoworks/dereference/FlavourInitialiser.java
// public class FlavourInitialiser {
// public FlavourInitialiser(DereferenceApplication application) {
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/MainInitialiser.java
// public class MainInitialiser {
// private final Application.ActivityLifecycleCallbacks initialiserCallbacks = new Application.ActivityLifecycleCallbacks() {
// @Override
// public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
// }
//
// @Override
// public void onActivityStarted(Activity activity) {
// }
//
// @Override
// public void onActivityResumed(Activity activity) {
// }
//
// @Override
// public void onActivityPaused(Activity activity) {
// }
//
// @Override
// public void onActivityStopped(Activity activity) {
// }
//
// @Override
// public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
// }
//
// @Override
// public void onActivityDestroyed(Activity activity) {
// }
// };
//
// public MainInitialiser(DereferenceApplication application, OkHttpClient okHttpClient) {
// application.registerActivityLifecycleCallbacks(initialiserCallbacks);
// LeakCanary.install(application);
// if (BuildConfig.DEBUG) {
// // FIXME no stetho for now
// // Stetho.initialize(Stetho.newInitializerBuilder(application)
// // .enableDumpapp(Stetho.defaultDumperPluginsProvider(application)).build());
// LumberYard lumberYard = LumberYard.getInstance(application);
// lumberYard.cleanUp();
// Timber.plant(lumberYard.tree());
// Timber.plant(new Timber.DebugTree());
// }
// }
// }
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/modules/ApplicationModule.java
import javax.inject.Singleton;
import android.content.Context;
import com.pacoworks.dereference.DereferenceApplication;
import com.pacoworks.dereference.FlavourInitialiser;
import com.pacoworks.dereference.MainInitialiser;
import com.squareup.okhttp.OkHttpClient;
import dagger.Module;
import dagger.Provides;
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.dependencies.modules;
@Module
public class ApplicationModule {
DereferenceApplication application;
public ApplicationModule(DereferenceApplication app) {
application = app;
}
@Provides
@Singleton
DereferenceApplication provideApplication() {
return application;
}
@Provides
@Singleton
Context provideContext() {
return application;
}
@Provides
@Singleton
|
MainInitialiser provideMainInitialiser(DereferenceApplication application,
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/dependencies/modules/ApplicationModule.java
|
// Path: app/src/main/java/com/pacoworks/dereference/DereferenceApplication.java
// public class DereferenceApplication extends Application {
// @Inject
// MainInitialiser mainInitialiser;
//
// @Inject
// FlavourInitialiser flavourInitialiser;
// private ApplicationInjectionComponent component;
//
// public static DereferenceApplication get(Context context) {
// return (DereferenceApplication)context.getApplicationContext();
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// buildComponentAndInject();
// }
//
// private void buildComponentAndInject() {
// component = ApplicationInjectionComponent.Initializer.init(this);
// /* Force initialisers to be created */
// component.inject(this);
// }
//
// public ApplicationInjectionComponent component() {
// return component;
// }
// }
//
// Path: app/src/whatever/java/com/pacoworks/dereference/FlavourInitialiser.java
// public class FlavourInitialiser {
// public FlavourInitialiser(DereferenceApplication application) {
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/MainInitialiser.java
// public class MainInitialiser {
// private final Application.ActivityLifecycleCallbacks initialiserCallbacks = new Application.ActivityLifecycleCallbacks() {
// @Override
// public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
// }
//
// @Override
// public void onActivityStarted(Activity activity) {
// }
//
// @Override
// public void onActivityResumed(Activity activity) {
// }
//
// @Override
// public void onActivityPaused(Activity activity) {
// }
//
// @Override
// public void onActivityStopped(Activity activity) {
// }
//
// @Override
// public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
// }
//
// @Override
// public void onActivityDestroyed(Activity activity) {
// }
// };
//
// public MainInitialiser(DereferenceApplication application, OkHttpClient okHttpClient) {
// application.registerActivityLifecycleCallbacks(initialiserCallbacks);
// LeakCanary.install(application);
// if (BuildConfig.DEBUG) {
// // FIXME no stetho for now
// // Stetho.initialize(Stetho.newInitializerBuilder(application)
// // .enableDumpapp(Stetho.defaultDumperPluginsProvider(application)).build());
// LumberYard lumberYard = LumberYard.getInstance(application);
// lumberYard.cleanUp();
// Timber.plant(lumberYard.tree());
// Timber.plant(new Timber.DebugTree());
// }
// }
// }
|
import javax.inject.Singleton;
import android.content.Context;
import com.pacoworks.dereference.DereferenceApplication;
import com.pacoworks.dereference.FlavourInitialiser;
import com.pacoworks.dereference.MainInitialiser;
import com.squareup.okhttp.OkHttpClient;
import dagger.Module;
import dagger.Provides;
|
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.dependencies.modules;
@Module
public class ApplicationModule {
DereferenceApplication application;
public ApplicationModule(DereferenceApplication app) {
application = app;
}
@Provides
@Singleton
DereferenceApplication provideApplication() {
return application;
}
@Provides
@Singleton
Context provideContext() {
return application;
}
@Provides
@Singleton
MainInitialiser provideMainInitialiser(DereferenceApplication application,
OkHttpClient okHttpClient) {
return new MainInitialiser(application, okHttpClient);
}
@Provides
@Singleton
|
// Path: app/src/main/java/com/pacoworks/dereference/DereferenceApplication.java
// public class DereferenceApplication extends Application {
// @Inject
// MainInitialiser mainInitialiser;
//
// @Inject
// FlavourInitialiser flavourInitialiser;
// private ApplicationInjectionComponent component;
//
// public static DereferenceApplication get(Context context) {
// return (DereferenceApplication)context.getApplicationContext();
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// buildComponentAndInject();
// }
//
// private void buildComponentAndInject() {
// component = ApplicationInjectionComponent.Initializer.init(this);
// /* Force initialisers to be created */
// component.inject(this);
// }
//
// public ApplicationInjectionComponent component() {
// return component;
// }
// }
//
// Path: app/src/whatever/java/com/pacoworks/dereference/FlavourInitialiser.java
// public class FlavourInitialiser {
// public FlavourInitialiser(DereferenceApplication application) {
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/MainInitialiser.java
// public class MainInitialiser {
// private final Application.ActivityLifecycleCallbacks initialiserCallbacks = new Application.ActivityLifecycleCallbacks() {
// @Override
// public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
// }
//
// @Override
// public void onActivityStarted(Activity activity) {
// }
//
// @Override
// public void onActivityResumed(Activity activity) {
// }
//
// @Override
// public void onActivityPaused(Activity activity) {
// }
//
// @Override
// public void onActivityStopped(Activity activity) {
// }
//
// @Override
// public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
// }
//
// @Override
// public void onActivityDestroyed(Activity activity) {
// }
// };
//
// public MainInitialiser(DereferenceApplication application, OkHttpClient okHttpClient) {
// application.registerActivityLifecycleCallbacks(initialiserCallbacks);
// LeakCanary.install(application);
// if (BuildConfig.DEBUG) {
// // FIXME no stetho for now
// // Stetho.initialize(Stetho.newInitializerBuilder(application)
// // .enableDumpapp(Stetho.defaultDumperPluginsProvider(application)).build());
// LumberYard lumberYard = LumberYard.getInstance(application);
// lumberYard.cleanUp();
// Timber.plant(lumberYard.tree());
// Timber.plant(new Timber.DebugTree());
// }
// }
// }
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/modules/ApplicationModule.java
import javax.inject.Singleton;
import android.content.Context;
import com.pacoworks.dereference.DereferenceApplication;
import com.pacoworks.dereference.FlavourInitialiser;
import com.pacoworks.dereference.MainInitialiser;
import com.squareup.okhttp.OkHttpClient;
import dagger.Module;
import dagger.Provides;
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.dependencies.modules;
@Module
public class ApplicationModule {
DereferenceApplication application;
public ApplicationModule(DereferenceApplication app) {
application = app;
}
@Provides
@Singleton
DereferenceApplication provideApplication() {
return application;
}
@Provides
@Singleton
Context provideContext() {
return application;
}
@Provides
@Singleton
MainInitialiser provideMainInitialiser(DereferenceApplication application,
OkHttpClient okHttpClient) {
return new MainInitialiser(application, okHttpClient);
}
@Provides
@Singleton
|
FlavourInitialiser provideFlavourInitialiser(DereferenceApplication application) {
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/screens/songkickdetails/SongkickDetailsState.java
|
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/skeleton/ZimpleBaseState.java
// public abstract class ZimpleBaseState implements Serializable {
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/model/Artist.java
// @ToString
// public class Artist implements Serializable {
// static final long serialVersionUID = 4653212L;
//
// @SerializedName("displayName")
// private final String displayName;
//
// @SerializedName("id")
// private final String id;
//
// @SerializedName("identifier")
// private final List<Identifier> identifier;
//
// @SerializedName("onTourUntil")
// private final String onTourUntil;
//
// @SerializedName("uri")
// private final String uri;
//
// public Artist(String displayName, String id, List<Identifier> identifier, String onTourUntil,
// String uri) {
// this.displayName = displayName;
// this.id = id;
// this.identifier = identifier;
// this.onTourUntil = onTourUntil;
// this.uri = uri;
// }
//
// public String getDisplayName() {
// return displayName;
// }
//
// public String getId() {
// return id;
// }
//
// public List<Identifier> getIdentifier() {
// return identifier;
// }
//
// public String getOnTourUntil() {
// return onTourUntil;
// }
//
// public String getUri() {
// return uri;
// }
// }
|
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.pacoworks.dereference.dependencies.skeleton.ZimpleBaseState;
import com.pacoworks.dereference.model.Artist;
|
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.screens.songkickdetails;
@Data
@EqualsAndHashCode(callSuper = false)
|
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/skeleton/ZimpleBaseState.java
// public abstract class ZimpleBaseState implements Serializable {
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/model/Artist.java
// @ToString
// public class Artist implements Serializable {
// static final long serialVersionUID = 4653212L;
//
// @SerializedName("displayName")
// private final String displayName;
//
// @SerializedName("id")
// private final String id;
//
// @SerializedName("identifier")
// private final List<Identifier> identifier;
//
// @SerializedName("onTourUntil")
// private final String onTourUntil;
//
// @SerializedName("uri")
// private final String uri;
//
// public Artist(String displayName, String id, List<Identifier> identifier, String onTourUntil,
// String uri) {
// this.displayName = displayName;
// this.id = id;
// this.identifier = identifier;
// this.onTourUntil = onTourUntil;
// this.uri = uri;
// }
//
// public String getDisplayName() {
// return displayName;
// }
//
// public String getId() {
// return id;
// }
//
// public List<Identifier> getIdentifier() {
// return identifier;
// }
//
// public String getOnTourUntil() {
// return onTourUntil;
// }
//
// public String getUri() {
// return uri;
// }
// }
// Path: app/src/main/java/com/pacoworks/dereference/screens/songkickdetails/SongkickDetailsState.java
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.pacoworks.dereference.dependencies.skeleton.ZimpleBaseState;
import com.pacoworks.dereference.model.Artist;
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.screens.songkickdetails;
@Data
@EqualsAndHashCode(callSuper = false)
|
public class SongkickDetailsState extends ZimpleBaseState {
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/screens/songkickdetails/SongkickDetailsState.java
|
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/skeleton/ZimpleBaseState.java
// public abstract class ZimpleBaseState implements Serializable {
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/model/Artist.java
// @ToString
// public class Artist implements Serializable {
// static final long serialVersionUID = 4653212L;
//
// @SerializedName("displayName")
// private final String displayName;
//
// @SerializedName("id")
// private final String id;
//
// @SerializedName("identifier")
// private final List<Identifier> identifier;
//
// @SerializedName("onTourUntil")
// private final String onTourUntil;
//
// @SerializedName("uri")
// private final String uri;
//
// public Artist(String displayName, String id, List<Identifier> identifier, String onTourUntil,
// String uri) {
// this.displayName = displayName;
// this.id = id;
// this.identifier = identifier;
// this.onTourUntil = onTourUntil;
// this.uri = uri;
// }
//
// public String getDisplayName() {
// return displayName;
// }
//
// public String getId() {
// return id;
// }
//
// public List<Identifier> getIdentifier() {
// return identifier;
// }
//
// public String getOnTourUntil() {
// return onTourUntil;
// }
//
// public String getUri() {
// return uri;
// }
// }
|
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.pacoworks.dereference.dependencies.skeleton.ZimpleBaseState;
import com.pacoworks.dereference.model.Artist;
|
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.screens.songkickdetails;
@Data
@EqualsAndHashCode(callSuper = false)
public class SongkickDetailsState extends ZimpleBaseState {
|
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/skeleton/ZimpleBaseState.java
// public abstract class ZimpleBaseState implements Serializable {
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/model/Artist.java
// @ToString
// public class Artist implements Serializable {
// static final long serialVersionUID = 4653212L;
//
// @SerializedName("displayName")
// private final String displayName;
//
// @SerializedName("id")
// private final String id;
//
// @SerializedName("identifier")
// private final List<Identifier> identifier;
//
// @SerializedName("onTourUntil")
// private final String onTourUntil;
//
// @SerializedName("uri")
// private final String uri;
//
// public Artist(String displayName, String id, List<Identifier> identifier, String onTourUntil,
// String uri) {
// this.displayName = displayName;
// this.id = id;
// this.identifier = identifier;
// this.onTourUntil = onTourUntil;
// this.uri = uri;
// }
//
// public String getDisplayName() {
// return displayName;
// }
//
// public String getId() {
// return id;
// }
//
// public List<Identifier> getIdentifier() {
// return identifier;
// }
//
// public String getOnTourUntil() {
// return onTourUntil;
// }
//
// public String getUri() {
// return uri;
// }
// }
// Path: app/src/main/java/com/pacoworks/dereference/screens/songkickdetails/SongkickDetailsState.java
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.pacoworks.dereference.dependencies.skeleton.ZimpleBaseState;
import com.pacoworks.dereference.model.Artist;
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.screens.songkickdetails;
@Data
@EqualsAndHashCode(callSuper = false)
public class SongkickDetailsState extends ZimpleBaseState {
|
private List<Artist> cached;
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/screens/songkicklist/ISongkickListUI.java
|
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/skeleton/IUi.java
// public interface IUi {
// Action1<? super Boolean> showOfflineOverlay();
//
// Action1<Throwable> toastError();
//
// Action1<String> toastMessage();
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/model/Artist.java
// @ToString
// public class Artist implements Serializable {
// static final long serialVersionUID = 4653212L;
//
// @SerializedName("displayName")
// private final String displayName;
//
// @SerializedName("id")
// private final String id;
//
// @SerializedName("identifier")
// private final List<Identifier> identifier;
//
// @SerializedName("onTourUntil")
// private final String onTourUntil;
//
// @SerializedName("uri")
// private final String uri;
//
// public Artist(String displayName, String id, List<Identifier> identifier, String onTourUntil,
// String uri) {
// this.displayName = displayName;
// this.id = id;
// this.identifier = identifier;
// this.onTourUntil = onTourUntil;
// this.uri = uri;
// }
//
// public String getDisplayName() {
// return displayName;
// }
//
// public String getId() {
// return id;
// }
//
// public List<Identifier> getIdentifier() {
// return identifier;
// }
//
// public String getOnTourUntil() {
// return onTourUntil;
// }
//
// public String getUri() {
// return uri;
// }
// }
|
import java.util.List;
import rx.Observable;
import rx.functions.Action1;
import com.pacoworks.dereference.dependencies.skeleton.IUi;
import com.pacoworks.dereference.model.Artist;
|
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.screens.songkicklist;
public interface ISongkickListUI extends IUi {
<T> Action1<T> showLoading();
<T> Action1<T> hideLoading();
|
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/skeleton/IUi.java
// public interface IUi {
// Action1<? super Boolean> showOfflineOverlay();
//
// Action1<Throwable> toastError();
//
// Action1<String> toastMessage();
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/model/Artist.java
// @ToString
// public class Artist implements Serializable {
// static final long serialVersionUID = 4653212L;
//
// @SerializedName("displayName")
// private final String displayName;
//
// @SerializedName("id")
// private final String id;
//
// @SerializedName("identifier")
// private final List<Identifier> identifier;
//
// @SerializedName("onTourUntil")
// private final String onTourUntil;
//
// @SerializedName("uri")
// private final String uri;
//
// public Artist(String displayName, String id, List<Identifier> identifier, String onTourUntil,
// String uri) {
// this.displayName = displayName;
// this.id = id;
// this.identifier = identifier;
// this.onTourUntil = onTourUntil;
// this.uri = uri;
// }
//
// public String getDisplayName() {
// return displayName;
// }
//
// public String getId() {
// return id;
// }
//
// public List<Identifier> getIdentifier() {
// return identifier;
// }
//
// public String getOnTourUntil() {
// return onTourUntil;
// }
//
// public String getUri() {
// return uri;
// }
// }
// Path: app/src/main/java/com/pacoworks/dereference/screens/songkicklist/ISongkickListUI.java
import java.util.List;
import rx.Observable;
import rx.functions.Action1;
import com.pacoworks.dereference.dependencies.skeleton.IUi;
import com.pacoworks.dereference.model.Artist;
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.screens.songkicklist;
public interface ISongkickListUI extends IUi {
<T> Action1<T> showLoading();
<T> Action1<T> hideLoading();
|
Observable<Artist> getArtistClicks();
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/screens/songkicklist/SongkickListInjectionComponent.java
|
// Path: app/src/whatever/java/com/pacoworks/dereference/ApplicationInjectionComponent.java
// @Singleton
// @Component(modules = {
// ApplicationModule.class, SerializationModule.class, NetworkModule.class
// })
// public interface ApplicationInjectionComponent extends DependencyDescription {
// final class Initializer {
// /* 10 MiB */
// private static final long CACHE_SIZE = 10 * 1024 * 1024;
//
// private Initializer() {
// /* No instances. */
// }
//
// static ApplicationInjectionComponent init(DereferenceApplication app) {
// return DaggerApplicationInjectionComponent
// .builder()
// .applicationModule(new ApplicationModule(app))
// .serializationModule(new SerializationModule())
// .networkModule(
// new NetworkModule(BuildConfig.ENDPOINT, app.getCacheDir(), CACHE_SIZE))
// .build();
// }
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/ActivityInjectionComponent.java
// public interface ActivityInjectionComponent<T extends ZimplBasePresenter> {
// void inject(T presenter);
//
// void inject(ZimplBaseActivity activity);
//
// Activity activity();
//
// ZimplBasePresenter presenter();
//
// Picasso picasso();
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/modules/ActivityModule.java
// @Module
// public class ActivityModule {
// private final Activity activity;
//
// private final Downloader okHttpDownloader;
//
// public ActivityModule(Activity activity, Downloader okHttpDownloader) {
// this.activity = activity;
// this.okHttpDownloader = okHttpDownloader;
// }
//
// @Provides
// @ForActivity
// Activity provideActivity() {
// return activity;
// }
//
// @Provides
// @ForActivity
// Picasso providePicasso() {
// return new Picasso.Builder(activity).downloader(okHttpDownloader).build();
// }
//
// @Provides
// @ForActivity
// Observable<ConnectivityStatus> provideReactiveNetwork() {
// return new ReactiveNetwork().observeConnectivity(activity);
// }
// }
|
import com.pacoworks.dereference.ApplicationInjectionComponent;
import com.pacoworks.dereference.dependencies.ActivityInjectionComponent;
import com.pacoworks.dereference.dependencies.ForActivity;
import com.pacoworks.dereference.dependencies.modules.ActivityModule;
import dagger.Component;
|
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.screens.songkicklist;
@ForActivity
@Component(dependencies = ApplicationInjectionComponent.class, modules = {
|
// Path: app/src/whatever/java/com/pacoworks/dereference/ApplicationInjectionComponent.java
// @Singleton
// @Component(modules = {
// ApplicationModule.class, SerializationModule.class, NetworkModule.class
// })
// public interface ApplicationInjectionComponent extends DependencyDescription {
// final class Initializer {
// /* 10 MiB */
// private static final long CACHE_SIZE = 10 * 1024 * 1024;
//
// private Initializer() {
// /* No instances. */
// }
//
// static ApplicationInjectionComponent init(DereferenceApplication app) {
// return DaggerApplicationInjectionComponent
// .builder()
// .applicationModule(new ApplicationModule(app))
// .serializationModule(new SerializationModule())
// .networkModule(
// new NetworkModule(BuildConfig.ENDPOINT, app.getCacheDir(), CACHE_SIZE))
// .build();
// }
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/ActivityInjectionComponent.java
// public interface ActivityInjectionComponent<T extends ZimplBasePresenter> {
// void inject(T presenter);
//
// void inject(ZimplBaseActivity activity);
//
// Activity activity();
//
// ZimplBasePresenter presenter();
//
// Picasso picasso();
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/modules/ActivityModule.java
// @Module
// public class ActivityModule {
// private final Activity activity;
//
// private final Downloader okHttpDownloader;
//
// public ActivityModule(Activity activity, Downloader okHttpDownloader) {
// this.activity = activity;
// this.okHttpDownloader = okHttpDownloader;
// }
//
// @Provides
// @ForActivity
// Activity provideActivity() {
// return activity;
// }
//
// @Provides
// @ForActivity
// Picasso providePicasso() {
// return new Picasso.Builder(activity).downloader(okHttpDownloader).build();
// }
//
// @Provides
// @ForActivity
// Observable<ConnectivityStatus> provideReactiveNetwork() {
// return new ReactiveNetwork().observeConnectivity(activity);
// }
// }
// Path: app/src/main/java/com/pacoworks/dereference/screens/songkicklist/SongkickListInjectionComponent.java
import com.pacoworks.dereference.ApplicationInjectionComponent;
import com.pacoworks.dereference.dependencies.ActivityInjectionComponent;
import com.pacoworks.dereference.dependencies.ForActivity;
import com.pacoworks.dereference.dependencies.modules.ActivityModule;
import dagger.Component;
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.screens.songkicklist;
@ForActivity
@Component(dependencies = ApplicationInjectionComponent.class, modules = {
|
ActivityModule.class, SongkickListModule.class
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/screens/songkicklist/SongkickListInjectionComponent.java
|
// Path: app/src/whatever/java/com/pacoworks/dereference/ApplicationInjectionComponent.java
// @Singleton
// @Component(modules = {
// ApplicationModule.class, SerializationModule.class, NetworkModule.class
// })
// public interface ApplicationInjectionComponent extends DependencyDescription {
// final class Initializer {
// /* 10 MiB */
// private static final long CACHE_SIZE = 10 * 1024 * 1024;
//
// private Initializer() {
// /* No instances. */
// }
//
// static ApplicationInjectionComponent init(DereferenceApplication app) {
// return DaggerApplicationInjectionComponent
// .builder()
// .applicationModule(new ApplicationModule(app))
// .serializationModule(new SerializationModule())
// .networkModule(
// new NetworkModule(BuildConfig.ENDPOINT, app.getCacheDir(), CACHE_SIZE))
// .build();
// }
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/ActivityInjectionComponent.java
// public interface ActivityInjectionComponent<T extends ZimplBasePresenter> {
// void inject(T presenter);
//
// void inject(ZimplBaseActivity activity);
//
// Activity activity();
//
// ZimplBasePresenter presenter();
//
// Picasso picasso();
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/modules/ActivityModule.java
// @Module
// public class ActivityModule {
// private final Activity activity;
//
// private final Downloader okHttpDownloader;
//
// public ActivityModule(Activity activity, Downloader okHttpDownloader) {
// this.activity = activity;
// this.okHttpDownloader = okHttpDownloader;
// }
//
// @Provides
// @ForActivity
// Activity provideActivity() {
// return activity;
// }
//
// @Provides
// @ForActivity
// Picasso providePicasso() {
// return new Picasso.Builder(activity).downloader(okHttpDownloader).build();
// }
//
// @Provides
// @ForActivity
// Observable<ConnectivityStatus> provideReactiveNetwork() {
// return new ReactiveNetwork().observeConnectivity(activity);
// }
// }
|
import com.pacoworks.dereference.ApplicationInjectionComponent;
import com.pacoworks.dereference.dependencies.ActivityInjectionComponent;
import com.pacoworks.dereference.dependencies.ForActivity;
import com.pacoworks.dereference.dependencies.modules.ActivityModule;
import dagger.Component;
|
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.screens.songkicklist;
@ForActivity
@Component(dependencies = ApplicationInjectionComponent.class, modules = {
ActivityModule.class, SongkickListModule.class
})
public interface SongkickListInjectionComponent extends
|
// Path: app/src/whatever/java/com/pacoworks/dereference/ApplicationInjectionComponent.java
// @Singleton
// @Component(modules = {
// ApplicationModule.class, SerializationModule.class, NetworkModule.class
// })
// public interface ApplicationInjectionComponent extends DependencyDescription {
// final class Initializer {
// /* 10 MiB */
// private static final long CACHE_SIZE = 10 * 1024 * 1024;
//
// private Initializer() {
// /* No instances. */
// }
//
// static ApplicationInjectionComponent init(DereferenceApplication app) {
// return DaggerApplicationInjectionComponent
// .builder()
// .applicationModule(new ApplicationModule(app))
// .serializationModule(new SerializationModule())
// .networkModule(
// new NetworkModule(BuildConfig.ENDPOINT, app.getCacheDir(), CACHE_SIZE))
// .build();
// }
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/ActivityInjectionComponent.java
// public interface ActivityInjectionComponent<T extends ZimplBasePresenter> {
// void inject(T presenter);
//
// void inject(ZimplBaseActivity activity);
//
// Activity activity();
//
// ZimplBasePresenter presenter();
//
// Picasso picasso();
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/modules/ActivityModule.java
// @Module
// public class ActivityModule {
// private final Activity activity;
//
// private final Downloader okHttpDownloader;
//
// public ActivityModule(Activity activity, Downloader okHttpDownloader) {
// this.activity = activity;
// this.okHttpDownloader = okHttpDownloader;
// }
//
// @Provides
// @ForActivity
// Activity provideActivity() {
// return activity;
// }
//
// @Provides
// @ForActivity
// Picasso providePicasso() {
// return new Picasso.Builder(activity).downloader(okHttpDownloader).build();
// }
//
// @Provides
// @ForActivity
// Observable<ConnectivityStatus> provideReactiveNetwork() {
// return new ReactiveNetwork().observeConnectivity(activity);
// }
// }
// Path: app/src/main/java/com/pacoworks/dereference/screens/songkicklist/SongkickListInjectionComponent.java
import com.pacoworks.dereference.ApplicationInjectionComponent;
import com.pacoworks.dereference.dependencies.ActivityInjectionComponent;
import com.pacoworks.dereference.dependencies.ForActivity;
import com.pacoworks.dereference.dependencies.modules.ActivityModule;
import dagger.Component;
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.screens.songkicklist;
@ForActivity
@Component(dependencies = ApplicationInjectionComponent.class, modules = {
ActivityModule.class, SongkickListModule.class
})
public interface SongkickListInjectionComponent extends
|
ActivityInjectionComponent<SongkickListPresenter> {
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/screens/songkicklist/SongkickListState.java
|
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/skeleton/ZimpleBaseState.java
// public abstract class ZimpleBaseState implements Serializable {
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/model/Artist.java
// @ToString
// public class Artist implements Serializable {
// static final long serialVersionUID = 4653212L;
//
// @SerializedName("displayName")
// private final String displayName;
//
// @SerializedName("id")
// private final String id;
//
// @SerializedName("identifier")
// private final List<Identifier> identifier;
//
// @SerializedName("onTourUntil")
// private final String onTourUntil;
//
// @SerializedName("uri")
// private final String uri;
//
// public Artist(String displayName, String id, List<Identifier> identifier, String onTourUntil,
// String uri) {
// this.displayName = displayName;
// this.id = id;
// this.identifier = identifier;
// this.onTourUntil = onTourUntil;
// this.uri = uri;
// }
//
// public String getDisplayName() {
// return displayName;
// }
//
// public String getId() {
// return id;
// }
//
// public List<Identifier> getIdentifier() {
// return identifier;
// }
//
// public String getOnTourUntil() {
// return onTourUntil;
// }
//
// public String getUri() {
// return uri;
// }
// }
|
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.pacoworks.dereference.dependencies.skeleton.ZimpleBaseState;
import com.pacoworks.dereference.model.Artist;
|
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.screens.songkicklist;
@EqualsAndHashCode(callSuper = false)
@Data
|
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/skeleton/ZimpleBaseState.java
// public abstract class ZimpleBaseState implements Serializable {
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/model/Artist.java
// @ToString
// public class Artist implements Serializable {
// static final long serialVersionUID = 4653212L;
//
// @SerializedName("displayName")
// private final String displayName;
//
// @SerializedName("id")
// private final String id;
//
// @SerializedName("identifier")
// private final List<Identifier> identifier;
//
// @SerializedName("onTourUntil")
// private final String onTourUntil;
//
// @SerializedName("uri")
// private final String uri;
//
// public Artist(String displayName, String id, List<Identifier> identifier, String onTourUntil,
// String uri) {
// this.displayName = displayName;
// this.id = id;
// this.identifier = identifier;
// this.onTourUntil = onTourUntil;
// this.uri = uri;
// }
//
// public String getDisplayName() {
// return displayName;
// }
//
// public String getId() {
// return id;
// }
//
// public List<Identifier> getIdentifier() {
// return identifier;
// }
//
// public String getOnTourUntil() {
// return onTourUntil;
// }
//
// public String getUri() {
// return uri;
// }
// }
// Path: app/src/main/java/com/pacoworks/dereference/screens/songkicklist/SongkickListState.java
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.pacoworks.dereference.dependencies.skeleton.ZimpleBaseState;
import com.pacoworks.dereference.model.Artist;
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.screens.songkicklist;
@EqualsAndHashCode(callSuper = false)
@Data
|
public class SongkickListState extends ZimpleBaseState {
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/screens/songkicklist/SongkickListState.java
|
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/skeleton/ZimpleBaseState.java
// public abstract class ZimpleBaseState implements Serializable {
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/model/Artist.java
// @ToString
// public class Artist implements Serializable {
// static final long serialVersionUID = 4653212L;
//
// @SerializedName("displayName")
// private final String displayName;
//
// @SerializedName("id")
// private final String id;
//
// @SerializedName("identifier")
// private final List<Identifier> identifier;
//
// @SerializedName("onTourUntil")
// private final String onTourUntil;
//
// @SerializedName("uri")
// private final String uri;
//
// public Artist(String displayName, String id, List<Identifier> identifier, String onTourUntil,
// String uri) {
// this.displayName = displayName;
// this.id = id;
// this.identifier = identifier;
// this.onTourUntil = onTourUntil;
// this.uri = uri;
// }
//
// public String getDisplayName() {
// return displayName;
// }
//
// public String getId() {
// return id;
// }
//
// public List<Identifier> getIdentifier() {
// return identifier;
// }
//
// public String getOnTourUntil() {
// return onTourUntil;
// }
//
// public String getUri() {
// return uri;
// }
// }
|
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.pacoworks.dereference.dependencies.skeleton.ZimpleBaseState;
import com.pacoworks.dereference.model.Artist;
|
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.screens.songkicklist;
@EqualsAndHashCode(callSuper = false)
@Data
public class SongkickListState extends ZimpleBaseState {
|
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/skeleton/ZimpleBaseState.java
// public abstract class ZimpleBaseState implements Serializable {
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/model/Artist.java
// @ToString
// public class Artist implements Serializable {
// static final long serialVersionUID = 4653212L;
//
// @SerializedName("displayName")
// private final String displayName;
//
// @SerializedName("id")
// private final String id;
//
// @SerializedName("identifier")
// private final List<Identifier> identifier;
//
// @SerializedName("onTourUntil")
// private final String onTourUntil;
//
// @SerializedName("uri")
// private final String uri;
//
// public Artist(String displayName, String id, List<Identifier> identifier, String onTourUntil,
// String uri) {
// this.displayName = displayName;
// this.id = id;
// this.identifier = identifier;
// this.onTourUntil = onTourUntil;
// this.uri = uri;
// }
//
// public String getDisplayName() {
// return displayName;
// }
//
// public String getId() {
// return id;
// }
//
// public List<Identifier> getIdentifier() {
// return identifier;
// }
//
// public String getOnTourUntil() {
// return onTourUntil;
// }
//
// public String getUri() {
// return uri;
// }
// }
// Path: app/src/main/java/com/pacoworks/dereference/screens/songkicklist/SongkickListState.java
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.pacoworks.dereference.dependencies.skeleton.ZimpleBaseState;
import com.pacoworks.dereference.model.Artist;
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.screens.songkicklist;
@EqualsAndHashCode(callSuper = false)
@Data
public class SongkickListState extends ZimpleBaseState {
|
private List<Artist> cached = new ArrayList<>();
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/ui/delegates/RelatedArtistDelegate.java
|
// Path: app/src/main/java/com/pacoworks/dereference/model/Artist.java
// @ToString
// public class Artist implements Serializable {
// static final long serialVersionUID = 4653212L;
//
// @SerializedName("displayName")
// private final String displayName;
//
// @SerializedName("id")
// private final String id;
//
// @SerializedName("identifier")
// private final List<Identifier> identifier;
//
// @SerializedName("onTourUntil")
// private final String onTourUntil;
//
// @SerializedName("uri")
// private final String uri;
//
// public Artist(String displayName, String id, List<Identifier> identifier, String onTourUntil,
// String uri) {
// this.displayName = displayName;
// this.id = id;
// this.identifier = identifier;
// this.onTourUntil = onTourUntil;
// this.uri = uri;
// }
//
// public String getDisplayName() {
// return displayName;
// }
//
// public String getId() {
// return id;
// }
//
// public List<Identifier> getIdentifier() {
// return identifier;
// }
//
// public String getOnTourUntil() {
// return onTourUntil;
// }
//
// public String getUri() {
// return uri;
// }
// }
|
import java.util.List;
import android.support.annotation.NonNull;
import com.pacoworks.dereference.model.Artist;
|
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.ui.delegates;
public class RelatedArtistDelegate extends ArtistDelegate {
public static final int TYPE = 98845;
@Override
|
// Path: app/src/main/java/com/pacoworks/dereference/model/Artist.java
// @ToString
// public class Artist implements Serializable {
// static final long serialVersionUID = 4653212L;
//
// @SerializedName("displayName")
// private final String displayName;
//
// @SerializedName("id")
// private final String id;
//
// @SerializedName("identifier")
// private final List<Identifier> identifier;
//
// @SerializedName("onTourUntil")
// private final String onTourUntil;
//
// @SerializedName("uri")
// private final String uri;
//
// public Artist(String displayName, String id, List<Identifier> identifier, String onTourUntil,
// String uri) {
// this.displayName = displayName;
// this.id = id;
// this.identifier = identifier;
// this.onTourUntil = onTourUntil;
// this.uri = uri;
// }
//
// public String getDisplayName() {
// return displayName;
// }
//
// public String getId() {
// return id;
// }
//
// public List<Identifier> getIdentifier() {
// return identifier;
// }
//
// public String getOnTourUntil() {
// return onTourUntil;
// }
//
// public String getUri() {
// return uri;
// }
// }
// Path: app/src/main/java/com/pacoworks/dereference/ui/delegates/RelatedArtistDelegate.java
import java.util.List;
import android.support.annotation.NonNull;
import com.pacoworks.dereference.model.Artist;
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.ui.delegates;
public class RelatedArtistDelegate extends ArtistDelegate {
public static final int TYPE = 98845;
@Override
|
public boolean isForViewType(@NonNull List<Artist> items, int position) {
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/screens/songkicklist/SongkickListModule.java
|
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/skeleton/ZimplBasePresenter.java
// public abstract class ZimplBasePresenter<T extends IUi, U extends ZimpleBaseState> {
// private final Class<U> stateClass;
//
// private final List<Subscription> pauseSubscriptions = new ArrayList<>();
//
// private final List<Subscription> destroySubscriptions = new ArrayList<>();
//
// @Inject
// @Getter(AccessLevel.PROTECTED)
// Gson gson;
//
// @Getter(AccessLevel.PROTECTED)
// private T ui;
//
// @Getter(AccessLevel.PROTECTED)
// private U state;
//
// public ZimplBasePresenter(Class<U> stateClass) {
// this.stateClass = stateClass;
// }
//
// // DEPENDENCY BINDING METHODS
// final void bindUi(T activity) {
// ui = activity;
// }
//
// final void unbindUi() {
// ui = null;
// }
//
// final void restoreState(String restoredState) {
// if (restoredState == null || restoredState.isEmpty()) {
// state = createNewState();
// } else {
// state = gson.fromJson(restoredState, stateClass);
// }
// }
//
// final String saveState() {
// return gson.toJson(state);
// }
//
// // LIFECYCLE
// final void createBase() {
// create();
// }
//
// final void resumeBase() {
// resume();
// }
//
// final void pauseBase() {
// unsubscribeAll(pauseSubscriptions);
// pause();
// }
//
// final void destroyBase() {
// unsubscribeAll(destroySubscriptions);
// destroy();
// }
//
// private void unsubscribeAll(List<Subscription> subscriptions) {
// for (Subscription subscription : subscriptions) {
// subscription.unsubscribe();
// }
// subscriptions.clear();
// }
//
// // PUBLIC API
// public void bindUntilPause(Subscription... subscriptions) {
// if (null != subscriptions) {
// Collections.addAll(pauseSubscriptions, subscriptions);
// }
// }
//
// public void bindUntilDestroy(Subscription... subscriptions) {
// if (null != subscriptions) {
// Collections.addAll(destroySubscriptions, subscriptions);
// }
// }
//
// // ABSTRACTS
// protected abstract U createNewState();
//
// public abstract void create();
//
// public abstract void resume();
//
// public abstract void pause();
//
// public abstract void destroy();
// }
|
import com.pacoworks.dereference.dependencies.skeleton.ZimplBasePresenter;
import dagger.Module;
import dagger.Provides;
|
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.screens.songkicklist;
@Module
public class SongkickListModule {
@Provides
|
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/skeleton/ZimplBasePresenter.java
// public abstract class ZimplBasePresenter<T extends IUi, U extends ZimpleBaseState> {
// private final Class<U> stateClass;
//
// private final List<Subscription> pauseSubscriptions = new ArrayList<>();
//
// private final List<Subscription> destroySubscriptions = new ArrayList<>();
//
// @Inject
// @Getter(AccessLevel.PROTECTED)
// Gson gson;
//
// @Getter(AccessLevel.PROTECTED)
// private T ui;
//
// @Getter(AccessLevel.PROTECTED)
// private U state;
//
// public ZimplBasePresenter(Class<U> stateClass) {
// this.stateClass = stateClass;
// }
//
// // DEPENDENCY BINDING METHODS
// final void bindUi(T activity) {
// ui = activity;
// }
//
// final void unbindUi() {
// ui = null;
// }
//
// final void restoreState(String restoredState) {
// if (restoredState == null || restoredState.isEmpty()) {
// state = createNewState();
// } else {
// state = gson.fromJson(restoredState, stateClass);
// }
// }
//
// final String saveState() {
// return gson.toJson(state);
// }
//
// // LIFECYCLE
// final void createBase() {
// create();
// }
//
// final void resumeBase() {
// resume();
// }
//
// final void pauseBase() {
// unsubscribeAll(pauseSubscriptions);
// pause();
// }
//
// final void destroyBase() {
// unsubscribeAll(destroySubscriptions);
// destroy();
// }
//
// private void unsubscribeAll(List<Subscription> subscriptions) {
// for (Subscription subscription : subscriptions) {
// subscription.unsubscribe();
// }
// subscriptions.clear();
// }
//
// // PUBLIC API
// public void bindUntilPause(Subscription... subscriptions) {
// if (null != subscriptions) {
// Collections.addAll(pauseSubscriptions, subscriptions);
// }
// }
//
// public void bindUntilDestroy(Subscription... subscriptions) {
// if (null != subscriptions) {
// Collections.addAll(destroySubscriptions, subscriptions);
// }
// }
//
// // ABSTRACTS
// protected abstract U createNewState();
//
// public abstract void create();
//
// public abstract void resume();
//
// public abstract void pause();
//
// public abstract void destroy();
// }
// Path: app/src/main/java/com/pacoworks/dereference/screens/songkicklist/SongkickListModule.java
import com.pacoworks.dereference.dependencies.skeleton.ZimplBasePresenter;
import dagger.Module;
import dagger.Provides;
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.screens.songkicklist;
@Module
public class SongkickListModule {
@Provides
|
ZimplBasePresenter providePresenter() {
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/dependencies/DependencyDescription.java
|
// Path: app/src/main/java/com/pacoworks/dereference/DereferenceApplication.java
// public class DereferenceApplication extends Application {
// @Inject
// MainInitialiser mainInitialiser;
//
// @Inject
// FlavourInitialiser flavourInitialiser;
// private ApplicationInjectionComponent component;
//
// public static DereferenceApplication get(Context context) {
// return (DereferenceApplication)context.getApplicationContext();
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// buildComponentAndInject();
// }
//
// private void buildComponentAndInject() {
// component = ApplicationInjectionComponent.Initializer.init(this);
// /* Force initialisers to be created */
// component.inject(this);
// }
//
// public ApplicationInjectionComponent component() {
// return component;
// }
// }
//
// Path: app/src/whatever/java/com/pacoworks/dereference/FlavourInitialiser.java
// public class FlavourInitialiser {
// public FlavourInitialiser(DereferenceApplication application) {
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/MainInitialiser.java
// public class MainInitialiser {
// private final Application.ActivityLifecycleCallbacks initialiserCallbacks = new Application.ActivityLifecycleCallbacks() {
// @Override
// public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
// }
//
// @Override
// public void onActivityStarted(Activity activity) {
// }
//
// @Override
// public void onActivityResumed(Activity activity) {
// }
//
// @Override
// public void onActivityPaused(Activity activity) {
// }
//
// @Override
// public void onActivityStopped(Activity activity) {
// }
//
// @Override
// public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
// }
//
// @Override
// public void onActivityDestroyed(Activity activity) {
// }
// };
//
// public MainInitialiser(DereferenceApplication application, OkHttpClient okHttpClient) {
// application.registerActivityLifecycleCallbacks(initialiserCallbacks);
// LeakCanary.install(application);
// if (BuildConfig.DEBUG) {
// // FIXME no stetho for now
// // Stetho.initialize(Stetho.newInitializerBuilder(application)
// // .enableDumpapp(Stetho.defaultDumperPluginsProvider(application)).build());
// LumberYard lumberYard = LumberYard.getInstance(application);
// lumberYard.cleanUp();
// Timber.plant(lumberYard.tree());
// Timber.plant(new Timber.DebugTree());
// }
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/network/SongkickApi.java
// public interface SongkickApi {
// @GET("search/artists.json")
// Observable<SearchResult> getSearchResult(@Query("apikey") String apikey,
// @Query("query") String url);
//
// @GET("artists/{artist_id}/similar_artists.json")
// Observable<SearchResult> getRelatedArtists(@Path("artist_id") String artistId,
// @Query("apikey") String apikey);
// }
|
import com.squareup.picasso.OkHttpDownloader;
import javax.inject.Named;
import retrofit.Retrofit;
import android.content.Context;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.pacoworks.dereference.DereferenceApplication;
import com.pacoworks.dereference.FlavourInitialiser;
import com.pacoworks.dereference.MainInitialiser;
import com.pacoworks.dereference.network.SongkickApi;
import com.squareup.okhttp.OkHttpClient;
|
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.dependencies;
public interface DependencyDescription {
void inject(DereferenceApplication application);
DereferenceApplication application();
Context baseContext();
|
// Path: app/src/main/java/com/pacoworks/dereference/DereferenceApplication.java
// public class DereferenceApplication extends Application {
// @Inject
// MainInitialiser mainInitialiser;
//
// @Inject
// FlavourInitialiser flavourInitialiser;
// private ApplicationInjectionComponent component;
//
// public static DereferenceApplication get(Context context) {
// return (DereferenceApplication)context.getApplicationContext();
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// buildComponentAndInject();
// }
//
// private void buildComponentAndInject() {
// component = ApplicationInjectionComponent.Initializer.init(this);
// /* Force initialisers to be created */
// component.inject(this);
// }
//
// public ApplicationInjectionComponent component() {
// return component;
// }
// }
//
// Path: app/src/whatever/java/com/pacoworks/dereference/FlavourInitialiser.java
// public class FlavourInitialiser {
// public FlavourInitialiser(DereferenceApplication application) {
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/MainInitialiser.java
// public class MainInitialiser {
// private final Application.ActivityLifecycleCallbacks initialiserCallbacks = new Application.ActivityLifecycleCallbacks() {
// @Override
// public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
// }
//
// @Override
// public void onActivityStarted(Activity activity) {
// }
//
// @Override
// public void onActivityResumed(Activity activity) {
// }
//
// @Override
// public void onActivityPaused(Activity activity) {
// }
//
// @Override
// public void onActivityStopped(Activity activity) {
// }
//
// @Override
// public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
// }
//
// @Override
// public void onActivityDestroyed(Activity activity) {
// }
// };
//
// public MainInitialiser(DereferenceApplication application, OkHttpClient okHttpClient) {
// application.registerActivityLifecycleCallbacks(initialiserCallbacks);
// LeakCanary.install(application);
// if (BuildConfig.DEBUG) {
// // FIXME no stetho for now
// // Stetho.initialize(Stetho.newInitializerBuilder(application)
// // .enableDumpapp(Stetho.defaultDumperPluginsProvider(application)).build());
// LumberYard lumberYard = LumberYard.getInstance(application);
// lumberYard.cleanUp();
// Timber.plant(lumberYard.tree());
// Timber.plant(new Timber.DebugTree());
// }
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/network/SongkickApi.java
// public interface SongkickApi {
// @GET("search/artists.json")
// Observable<SearchResult> getSearchResult(@Query("apikey") String apikey,
// @Query("query") String url);
//
// @GET("artists/{artist_id}/similar_artists.json")
// Observable<SearchResult> getRelatedArtists(@Path("artist_id") String artistId,
// @Query("apikey") String apikey);
// }
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/DependencyDescription.java
import com.squareup.picasso.OkHttpDownloader;
import javax.inject.Named;
import retrofit.Retrofit;
import android.content.Context;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.pacoworks.dereference.DereferenceApplication;
import com.pacoworks.dereference.FlavourInitialiser;
import com.pacoworks.dereference.MainInitialiser;
import com.pacoworks.dereference.network.SongkickApi;
import com.squareup.okhttp.OkHttpClient;
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.dependencies;
public interface DependencyDescription {
void inject(DereferenceApplication application);
DereferenceApplication application();
Context baseContext();
|
MainInitialiser initialiser();
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/dependencies/DependencyDescription.java
|
// Path: app/src/main/java/com/pacoworks/dereference/DereferenceApplication.java
// public class DereferenceApplication extends Application {
// @Inject
// MainInitialiser mainInitialiser;
//
// @Inject
// FlavourInitialiser flavourInitialiser;
// private ApplicationInjectionComponent component;
//
// public static DereferenceApplication get(Context context) {
// return (DereferenceApplication)context.getApplicationContext();
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// buildComponentAndInject();
// }
//
// private void buildComponentAndInject() {
// component = ApplicationInjectionComponent.Initializer.init(this);
// /* Force initialisers to be created */
// component.inject(this);
// }
//
// public ApplicationInjectionComponent component() {
// return component;
// }
// }
//
// Path: app/src/whatever/java/com/pacoworks/dereference/FlavourInitialiser.java
// public class FlavourInitialiser {
// public FlavourInitialiser(DereferenceApplication application) {
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/MainInitialiser.java
// public class MainInitialiser {
// private final Application.ActivityLifecycleCallbacks initialiserCallbacks = new Application.ActivityLifecycleCallbacks() {
// @Override
// public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
// }
//
// @Override
// public void onActivityStarted(Activity activity) {
// }
//
// @Override
// public void onActivityResumed(Activity activity) {
// }
//
// @Override
// public void onActivityPaused(Activity activity) {
// }
//
// @Override
// public void onActivityStopped(Activity activity) {
// }
//
// @Override
// public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
// }
//
// @Override
// public void onActivityDestroyed(Activity activity) {
// }
// };
//
// public MainInitialiser(DereferenceApplication application, OkHttpClient okHttpClient) {
// application.registerActivityLifecycleCallbacks(initialiserCallbacks);
// LeakCanary.install(application);
// if (BuildConfig.DEBUG) {
// // FIXME no stetho for now
// // Stetho.initialize(Stetho.newInitializerBuilder(application)
// // .enableDumpapp(Stetho.defaultDumperPluginsProvider(application)).build());
// LumberYard lumberYard = LumberYard.getInstance(application);
// lumberYard.cleanUp();
// Timber.plant(lumberYard.tree());
// Timber.plant(new Timber.DebugTree());
// }
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/network/SongkickApi.java
// public interface SongkickApi {
// @GET("search/artists.json")
// Observable<SearchResult> getSearchResult(@Query("apikey") String apikey,
// @Query("query") String url);
//
// @GET("artists/{artist_id}/similar_artists.json")
// Observable<SearchResult> getRelatedArtists(@Path("artist_id") String artistId,
// @Query("apikey") String apikey);
// }
|
import com.squareup.picasso.OkHttpDownloader;
import javax.inject.Named;
import retrofit.Retrofit;
import android.content.Context;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.pacoworks.dereference.DereferenceApplication;
import com.pacoworks.dereference.FlavourInitialiser;
import com.pacoworks.dereference.MainInitialiser;
import com.pacoworks.dereference.network.SongkickApi;
import com.squareup.okhttp.OkHttpClient;
|
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.dependencies;
public interface DependencyDescription {
void inject(DereferenceApplication application);
DereferenceApplication application();
Context baseContext();
MainInitialiser initialiser();
|
// Path: app/src/main/java/com/pacoworks/dereference/DereferenceApplication.java
// public class DereferenceApplication extends Application {
// @Inject
// MainInitialiser mainInitialiser;
//
// @Inject
// FlavourInitialiser flavourInitialiser;
// private ApplicationInjectionComponent component;
//
// public static DereferenceApplication get(Context context) {
// return (DereferenceApplication)context.getApplicationContext();
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// buildComponentAndInject();
// }
//
// private void buildComponentAndInject() {
// component = ApplicationInjectionComponent.Initializer.init(this);
// /* Force initialisers to be created */
// component.inject(this);
// }
//
// public ApplicationInjectionComponent component() {
// return component;
// }
// }
//
// Path: app/src/whatever/java/com/pacoworks/dereference/FlavourInitialiser.java
// public class FlavourInitialiser {
// public FlavourInitialiser(DereferenceApplication application) {
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/MainInitialiser.java
// public class MainInitialiser {
// private final Application.ActivityLifecycleCallbacks initialiserCallbacks = new Application.ActivityLifecycleCallbacks() {
// @Override
// public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
// }
//
// @Override
// public void onActivityStarted(Activity activity) {
// }
//
// @Override
// public void onActivityResumed(Activity activity) {
// }
//
// @Override
// public void onActivityPaused(Activity activity) {
// }
//
// @Override
// public void onActivityStopped(Activity activity) {
// }
//
// @Override
// public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
// }
//
// @Override
// public void onActivityDestroyed(Activity activity) {
// }
// };
//
// public MainInitialiser(DereferenceApplication application, OkHttpClient okHttpClient) {
// application.registerActivityLifecycleCallbacks(initialiserCallbacks);
// LeakCanary.install(application);
// if (BuildConfig.DEBUG) {
// // FIXME no stetho for now
// // Stetho.initialize(Stetho.newInitializerBuilder(application)
// // .enableDumpapp(Stetho.defaultDumperPluginsProvider(application)).build());
// LumberYard lumberYard = LumberYard.getInstance(application);
// lumberYard.cleanUp();
// Timber.plant(lumberYard.tree());
// Timber.plant(new Timber.DebugTree());
// }
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/network/SongkickApi.java
// public interface SongkickApi {
// @GET("search/artists.json")
// Observable<SearchResult> getSearchResult(@Query("apikey") String apikey,
// @Query("query") String url);
//
// @GET("artists/{artist_id}/similar_artists.json")
// Observable<SearchResult> getRelatedArtists(@Path("artist_id") String artistId,
// @Query("apikey") String apikey);
// }
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/DependencyDescription.java
import com.squareup.picasso.OkHttpDownloader;
import javax.inject.Named;
import retrofit.Retrofit;
import android.content.Context;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.pacoworks.dereference.DereferenceApplication;
import com.pacoworks.dereference.FlavourInitialiser;
import com.pacoworks.dereference.MainInitialiser;
import com.pacoworks.dereference.network.SongkickApi;
import com.squareup.okhttp.OkHttpClient;
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.dependencies;
public interface DependencyDescription {
void inject(DereferenceApplication application);
DereferenceApplication application();
Context baseContext();
MainInitialiser initialiser();
|
FlavourInitialiser flavourInitialiser();
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/dependencies/DependencyDescription.java
|
// Path: app/src/main/java/com/pacoworks/dereference/DereferenceApplication.java
// public class DereferenceApplication extends Application {
// @Inject
// MainInitialiser mainInitialiser;
//
// @Inject
// FlavourInitialiser flavourInitialiser;
// private ApplicationInjectionComponent component;
//
// public static DereferenceApplication get(Context context) {
// return (DereferenceApplication)context.getApplicationContext();
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// buildComponentAndInject();
// }
//
// private void buildComponentAndInject() {
// component = ApplicationInjectionComponent.Initializer.init(this);
// /* Force initialisers to be created */
// component.inject(this);
// }
//
// public ApplicationInjectionComponent component() {
// return component;
// }
// }
//
// Path: app/src/whatever/java/com/pacoworks/dereference/FlavourInitialiser.java
// public class FlavourInitialiser {
// public FlavourInitialiser(DereferenceApplication application) {
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/MainInitialiser.java
// public class MainInitialiser {
// private final Application.ActivityLifecycleCallbacks initialiserCallbacks = new Application.ActivityLifecycleCallbacks() {
// @Override
// public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
// }
//
// @Override
// public void onActivityStarted(Activity activity) {
// }
//
// @Override
// public void onActivityResumed(Activity activity) {
// }
//
// @Override
// public void onActivityPaused(Activity activity) {
// }
//
// @Override
// public void onActivityStopped(Activity activity) {
// }
//
// @Override
// public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
// }
//
// @Override
// public void onActivityDestroyed(Activity activity) {
// }
// };
//
// public MainInitialiser(DereferenceApplication application, OkHttpClient okHttpClient) {
// application.registerActivityLifecycleCallbacks(initialiserCallbacks);
// LeakCanary.install(application);
// if (BuildConfig.DEBUG) {
// // FIXME no stetho for now
// // Stetho.initialize(Stetho.newInitializerBuilder(application)
// // .enableDumpapp(Stetho.defaultDumperPluginsProvider(application)).build());
// LumberYard lumberYard = LumberYard.getInstance(application);
// lumberYard.cleanUp();
// Timber.plant(lumberYard.tree());
// Timber.plant(new Timber.DebugTree());
// }
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/network/SongkickApi.java
// public interface SongkickApi {
// @GET("search/artists.json")
// Observable<SearchResult> getSearchResult(@Query("apikey") String apikey,
// @Query("query") String url);
//
// @GET("artists/{artist_id}/similar_artists.json")
// Observable<SearchResult> getRelatedArtists(@Path("artist_id") String artistId,
// @Query("apikey") String apikey);
// }
|
import com.squareup.picasso.OkHttpDownloader;
import javax.inject.Named;
import retrofit.Retrofit;
import android.content.Context;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.pacoworks.dereference.DereferenceApplication;
import com.pacoworks.dereference.FlavourInitialiser;
import com.pacoworks.dereference.MainInitialiser;
import com.pacoworks.dereference.network.SongkickApi;
import com.squareup.okhttp.OkHttpClient;
|
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.dependencies;
public interface DependencyDescription {
void inject(DereferenceApplication application);
DereferenceApplication application();
Context baseContext();
MainInitialiser initialiser();
FlavourInitialiser flavourInitialiser();
Gson gsonDefault();
@Named("default")
ObjectMapper jacksonDefault();
@Named("unknown")
ObjectMapper jacksonUnknown();
@Named("fields")
ObjectMapper jacksonFieldsOnly();
OkHttpClient okHttpClient();
OkHttpDownloader okHttpDownloader();
@Named("songkick")
Retrofit getSongkickRetrofit();
|
// Path: app/src/main/java/com/pacoworks/dereference/DereferenceApplication.java
// public class DereferenceApplication extends Application {
// @Inject
// MainInitialiser mainInitialiser;
//
// @Inject
// FlavourInitialiser flavourInitialiser;
// private ApplicationInjectionComponent component;
//
// public static DereferenceApplication get(Context context) {
// return (DereferenceApplication)context.getApplicationContext();
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// buildComponentAndInject();
// }
//
// private void buildComponentAndInject() {
// component = ApplicationInjectionComponent.Initializer.init(this);
// /* Force initialisers to be created */
// component.inject(this);
// }
//
// public ApplicationInjectionComponent component() {
// return component;
// }
// }
//
// Path: app/src/whatever/java/com/pacoworks/dereference/FlavourInitialiser.java
// public class FlavourInitialiser {
// public FlavourInitialiser(DereferenceApplication application) {
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/MainInitialiser.java
// public class MainInitialiser {
// private final Application.ActivityLifecycleCallbacks initialiserCallbacks = new Application.ActivityLifecycleCallbacks() {
// @Override
// public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
// }
//
// @Override
// public void onActivityStarted(Activity activity) {
// }
//
// @Override
// public void onActivityResumed(Activity activity) {
// }
//
// @Override
// public void onActivityPaused(Activity activity) {
// }
//
// @Override
// public void onActivityStopped(Activity activity) {
// }
//
// @Override
// public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
// }
//
// @Override
// public void onActivityDestroyed(Activity activity) {
// }
// };
//
// public MainInitialiser(DereferenceApplication application, OkHttpClient okHttpClient) {
// application.registerActivityLifecycleCallbacks(initialiserCallbacks);
// LeakCanary.install(application);
// if (BuildConfig.DEBUG) {
// // FIXME no stetho for now
// // Stetho.initialize(Stetho.newInitializerBuilder(application)
// // .enableDumpapp(Stetho.defaultDumperPluginsProvider(application)).build());
// LumberYard lumberYard = LumberYard.getInstance(application);
// lumberYard.cleanUp();
// Timber.plant(lumberYard.tree());
// Timber.plant(new Timber.DebugTree());
// }
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/network/SongkickApi.java
// public interface SongkickApi {
// @GET("search/artists.json")
// Observable<SearchResult> getSearchResult(@Query("apikey") String apikey,
// @Query("query") String url);
//
// @GET("artists/{artist_id}/similar_artists.json")
// Observable<SearchResult> getRelatedArtists(@Path("artist_id") String artistId,
// @Query("apikey") String apikey);
// }
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/DependencyDescription.java
import com.squareup.picasso.OkHttpDownloader;
import javax.inject.Named;
import retrofit.Retrofit;
import android.content.Context;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.pacoworks.dereference.DereferenceApplication;
import com.pacoworks.dereference.FlavourInitialiser;
import com.pacoworks.dereference.MainInitialiser;
import com.pacoworks.dereference.network.SongkickApi;
import com.squareup.okhttp.OkHttpClient;
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.dependencies;
public interface DependencyDescription {
void inject(DereferenceApplication application);
DereferenceApplication application();
Context baseContext();
MainInitialiser initialiser();
FlavourInitialiser flavourInitialiser();
Gson gsonDefault();
@Named("default")
ObjectMapper jacksonDefault();
@Named("unknown")
ObjectMapper jacksonUnknown();
@Named("fields")
ObjectMapper jacksonFieldsOnly();
OkHttpClient okHttpClient();
OkHttpDownloader okHttpDownloader();
@Named("songkick")
Retrofit getSongkickRetrofit();
|
SongkickApi songkickApi();
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/dependencies/modules/NetworkModule.java
|
// Path: app/src/main/java/com/pacoworks/dereference/network/LoggerInterceptor.java
// public class LoggerInterceptor implements Interceptor {
// @Override
// public Response intercept(Chain chain) throws IOException {
// Timber.d("Started request ==> %s", chain.request().url().toString());
// return chain.proceed(chain.request());
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/network/SongkickApi.java
// public interface SongkickApi {
// @GET("search/artists.json")
// Observable<SearchResult> getSearchResult(@Query("apikey") String apikey,
// @Query("query") String url);
//
// @GET("artists/{artist_id}/similar_artists.json")
// Observable<SearchResult> getRelatedArtists(@Path("artist_id") String artistId,
// @Query("apikey") String apikey);
// }
|
import com.pacoworks.dereference.network.SongkickApi;
import com.squareup.okhttp.Cache;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.picasso.OkHttpDownloader;
import dagger.Module;
import dagger.Provides;
import java.io.File;
import java.util.concurrent.TimeUnit;
import javax.inject.Named;
import javax.inject.Singleton;
import retrofit.GsonConverterFactory;
import retrofit.Retrofit;
import retrofit.RxJavaCallAdapterFactory;
import com.facebook.stetho.okhttp.StethoInterceptor;
import com.google.gson.Gson;
import com.pacoworks.dereference.network.LoggerInterceptor;
|
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.dependencies.modules;
@Module(includes = SerializationModule.class)
public class NetworkModule {
static final int DEFAULT_READ_TIMEOUT_MILLIS = 20 * 1000; // 20s
static final int DEFAULT_WRITE_TIMEOUT_MILLIS = 20 * 1000; // 20s
static final int DEFAULT_CONNECT_TIMEOUT_MILLIS = 15 * 1000; // 15s
private final String endpointUrl;
private final long cacheSize;
private File cacheDir;
public NetworkModule(String endpointUrl, File cacheDir, long cacheSize) {
this.cacheDir = cacheDir;
this.endpointUrl = endpointUrl;
this.cacheSize = cacheSize;
}
@Provides
@Singleton
|
// Path: app/src/main/java/com/pacoworks/dereference/network/LoggerInterceptor.java
// public class LoggerInterceptor implements Interceptor {
// @Override
// public Response intercept(Chain chain) throws IOException {
// Timber.d("Started request ==> %s", chain.request().url().toString());
// return chain.proceed(chain.request());
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/network/SongkickApi.java
// public interface SongkickApi {
// @GET("search/artists.json")
// Observable<SearchResult> getSearchResult(@Query("apikey") String apikey,
// @Query("query") String url);
//
// @GET("artists/{artist_id}/similar_artists.json")
// Observable<SearchResult> getRelatedArtists(@Path("artist_id") String artistId,
// @Query("apikey") String apikey);
// }
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/modules/NetworkModule.java
import com.pacoworks.dereference.network.SongkickApi;
import com.squareup.okhttp.Cache;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.picasso.OkHttpDownloader;
import dagger.Module;
import dagger.Provides;
import java.io.File;
import java.util.concurrent.TimeUnit;
import javax.inject.Named;
import javax.inject.Singleton;
import retrofit.GsonConverterFactory;
import retrofit.Retrofit;
import retrofit.RxJavaCallAdapterFactory;
import com.facebook.stetho.okhttp.StethoInterceptor;
import com.google.gson.Gson;
import com.pacoworks.dereference.network.LoggerInterceptor;
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.dependencies.modules;
@Module(includes = SerializationModule.class)
public class NetworkModule {
static final int DEFAULT_READ_TIMEOUT_MILLIS = 20 * 1000; // 20s
static final int DEFAULT_WRITE_TIMEOUT_MILLIS = 20 * 1000; // 20s
static final int DEFAULT_CONNECT_TIMEOUT_MILLIS = 15 * 1000; // 15s
private final String endpointUrl;
private final long cacheSize;
private File cacheDir;
public NetworkModule(String endpointUrl, File cacheDir, long cacheSize) {
this.cacheDir = cacheDir;
this.endpointUrl = endpointUrl;
this.cacheSize = cacheSize;
}
@Provides
@Singleton
|
OkHttpClient provideOkHttp(final Cache cache, LoggerInterceptor loggerInterceptor,
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/dependencies/modules/NetworkModule.java
|
// Path: app/src/main/java/com/pacoworks/dereference/network/LoggerInterceptor.java
// public class LoggerInterceptor implements Interceptor {
// @Override
// public Response intercept(Chain chain) throws IOException {
// Timber.d("Started request ==> %s", chain.request().url().toString());
// return chain.proceed(chain.request());
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/network/SongkickApi.java
// public interface SongkickApi {
// @GET("search/artists.json")
// Observable<SearchResult> getSearchResult(@Query("apikey") String apikey,
// @Query("query") String url);
//
// @GET("artists/{artist_id}/similar_artists.json")
// Observable<SearchResult> getRelatedArtists(@Path("artist_id") String artistId,
// @Query("apikey") String apikey);
// }
|
import com.pacoworks.dereference.network.SongkickApi;
import com.squareup.okhttp.Cache;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.picasso.OkHttpDownloader;
import dagger.Module;
import dagger.Provides;
import java.io.File;
import java.util.concurrent.TimeUnit;
import javax.inject.Named;
import javax.inject.Singleton;
import retrofit.GsonConverterFactory;
import retrofit.Retrofit;
import retrofit.RxJavaCallAdapterFactory;
import com.facebook.stetho.okhttp.StethoInterceptor;
import com.google.gson.Gson;
import com.pacoworks.dereference.network.LoggerInterceptor;
|
@Provides
@Singleton
Cache provideCache() {
return new Cache(cacheDir, cacheSize);
}
@Provides
@Singleton
StethoInterceptor stethoInterceptor() {
return new StethoInterceptor();
}
@Provides
@Singleton
LoggerInterceptor loggerInterceptor() {
return new LoggerInterceptor();
}
@Provides
@Named("songkick")
@Singleton
Retrofit provideRetrofitSongkick(OkHttpClient client, Gson gson) {
return new Retrofit.Builder().client(client).baseUrl(endpointUrl)
.addConverterFactory(GsonConverterFactory.create(gson))
.addCallAdapterFactory(RxJavaCallAdapterFactory.create()).build();
}
@Provides
@Singleton
|
// Path: app/src/main/java/com/pacoworks/dereference/network/LoggerInterceptor.java
// public class LoggerInterceptor implements Interceptor {
// @Override
// public Response intercept(Chain chain) throws IOException {
// Timber.d("Started request ==> %s", chain.request().url().toString());
// return chain.proceed(chain.request());
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/network/SongkickApi.java
// public interface SongkickApi {
// @GET("search/artists.json")
// Observable<SearchResult> getSearchResult(@Query("apikey") String apikey,
// @Query("query") String url);
//
// @GET("artists/{artist_id}/similar_artists.json")
// Observable<SearchResult> getRelatedArtists(@Path("artist_id") String artistId,
// @Query("apikey") String apikey);
// }
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/modules/NetworkModule.java
import com.pacoworks.dereference.network.SongkickApi;
import com.squareup.okhttp.Cache;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.picasso.OkHttpDownloader;
import dagger.Module;
import dagger.Provides;
import java.io.File;
import java.util.concurrent.TimeUnit;
import javax.inject.Named;
import javax.inject.Singleton;
import retrofit.GsonConverterFactory;
import retrofit.Retrofit;
import retrofit.RxJavaCallAdapterFactory;
import com.facebook.stetho.okhttp.StethoInterceptor;
import com.google.gson.Gson;
import com.pacoworks.dereference.network.LoggerInterceptor;
@Provides
@Singleton
Cache provideCache() {
return new Cache(cacheDir, cacheSize);
}
@Provides
@Singleton
StethoInterceptor stethoInterceptor() {
return new StethoInterceptor();
}
@Provides
@Singleton
LoggerInterceptor loggerInterceptor() {
return new LoggerInterceptor();
}
@Provides
@Named("songkick")
@Singleton
Retrofit provideRetrofitSongkick(OkHttpClient client, Gson gson) {
return new Retrofit.Builder().client(client).baseUrl(endpointUrl)
.addConverterFactory(GsonConverterFactory.create(gson))
.addCallAdapterFactory(RxJavaCallAdapterFactory.create()).build();
}
@Provides
@Singleton
|
SongkickApi provideSongkickApi(@Named("songkick") Retrofit retrofit) {
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/screens/songkickdetails/SongkickDetailsModule.java
|
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/skeleton/ZimplBasePresenter.java
// public abstract class ZimplBasePresenter<T extends IUi, U extends ZimpleBaseState> {
// private final Class<U> stateClass;
//
// private final List<Subscription> pauseSubscriptions = new ArrayList<>();
//
// private final List<Subscription> destroySubscriptions = new ArrayList<>();
//
// @Inject
// @Getter(AccessLevel.PROTECTED)
// Gson gson;
//
// @Getter(AccessLevel.PROTECTED)
// private T ui;
//
// @Getter(AccessLevel.PROTECTED)
// private U state;
//
// public ZimplBasePresenter(Class<U> stateClass) {
// this.stateClass = stateClass;
// }
//
// // DEPENDENCY BINDING METHODS
// final void bindUi(T activity) {
// ui = activity;
// }
//
// final void unbindUi() {
// ui = null;
// }
//
// final void restoreState(String restoredState) {
// if (restoredState == null || restoredState.isEmpty()) {
// state = createNewState();
// } else {
// state = gson.fromJson(restoredState, stateClass);
// }
// }
//
// final String saveState() {
// return gson.toJson(state);
// }
//
// // LIFECYCLE
// final void createBase() {
// create();
// }
//
// final void resumeBase() {
// resume();
// }
//
// final void pauseBase() {
// unsubscribeAll(pauseSubscriptions);
// pause();
// }
//
// final void destroyBase() {
// unsubscribeAll(destroySubscriptions);
// destroy();
// }
//
// private void unsubscribeAll(List<Subscription> subscriptions) {
// for (Subscription subscription : subscriptions) {
// subscription.unsubscribe();
// }
// subscriptions.clear();
// }
//
// // PUBLIC API
// public void bindUntilPause(Subscription... subscriptions) {
// if (null != subscriptions) {
// Collections.addAll(pauseSubscriptions, subscriptions);
// }
// }
//
// public void bindUntilDestroy(Subscription... subscriptions) {
// if (null != subscriptions) {
// Collections.addAll(destroySubscriptions, subscriptions);
// }
// }
//
// // ABSTRACTS
// protected abstract U createNewState();
//
// public abstract void create();
//
// public abstract void resume();
//
// public abstract void pause();
//
// public abstract void destroy();
// }
|
import com.pacoworks.dereference.dependencies.skeleton.ZimplBasePresenter;
import dagger.Module;
import dagger.Provides;
|
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.screens.songkickdetails;
@Module
public class SongkickDetailsModule {
@Provides
|
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/skeleton/ZimplBasePresenter.java
// public abstract class ZimplBasePresenter<T extends IUi, U extends ZimpleBaseState> {
// private final Class<U> stateClass;
//
// private final List<Subscription> pauseSubscriptions = new ArrayList<>();
//
// private final List<Subscription> destroySubscriptions = new ArrayList<>();
//
// @Inject
// @Getter(AccessLevel.PROTECTED)
// Gson gson;
//
// @Getter(AccessLevel.PROTECTED)
// private T ui;
//
// @Getter(AccessLevel.PROTECTED)
// private U state;
//
// public ZimplBasePresenter(Class<U> stateClass) {
// this.stateClass = stateClass;
// }
//
// // DEPENDENCY BINDING METHODS
// final void bindUi(T activity) {
// ui = activity;
// }
//
// final void unbindUi() {
// ui = null;
// }
//
// final void restoreState(String restoredState) {
// if (restoredState == null || restoredState.isEmpty()) {
// state = createNewState();
// } else {
// state = gson.fromJson(restoredState, stateClass);
// }
// }
//
// final String saveState() {
// return gson.toJson(state);
// }
//
// // LIFECYCLE
// final void createBase() {
// create();
// }
//
// final void resumeBase() {
// resume();
// }
//
// final void pauseBase() {
// unsubscribeAll(pauseSubscriptions);
// pause();
// }
//
// final void destroyBase() {
// unsubscribeAll(destroySubscriptions);
// destroy();
// }
//
// private void unsubscribeAll(List<Subscription> subscriptions) {
// for (Subscription subscription : subscriptions) {
// subscription.unsubscribe();
// }
// subscriptions.clear();
// }
//
// // PUBLIC API
// public void bindUntilPause(Subscription... subscriptions) {
// if (null != subscriptions) {
// Collections.addAll(pauseSubscriptions, subscriptions);
// }
// }
//
// public void bindUntilDestroy(Subscription... subscriptions) {
// if (null != subscriptions) {
// Collections.addAll(destroySubscriptions, subscriptions);
// }
// }
//
// // ABSTRACTS
// protected abstract U createNewState();
//
// public abstract void create();
//
// public abstract void resume();
//
// public abstract void pause();
//
// public abstract void destroy();
// }
// Path: app/src/main/java/com/pacoworks/dereference/screens/songkickdetails/SongkickDetailsModule.java
import com.pacoworks.dereference.dependencies.skeleton.ZimplBasePresenter;
import dagger.Module;
import dagger.Provides;
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.screens.songkickdetails;
@Module
public class SongkickDetailsModule {
@Provides
|
ZimplBasePresenter providePresenter() {
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/screens/songkickdetails/ISongkickDetailsUI.java
|
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/skeleton/IUi.java
// public interface IUi {
// Action1<? super Boolean> showOfflineOverlay();
//
// Action1<Throwable> toastError();
//
// Action1<String> toastMessage();
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/model/Artist.java
// @ToString
// public class Artist implements Serializable {
// static final long serialVersionUID = 4653212L;
//
// @SerializedName("displayName")
// private final String displayName;
//
// @SerializedName("id")
// private final String id;
//
// @SerializedName("identifier")
// private final List<Identifier> identifier;
//
// @SerializedName("onTourUntil")
// private final String onTourUntil;
//
// @SerializedName("uri")
// private final String uri;
//
// public Artist(String displayName, String id, List<Identifier> identifier, String onTourUntil,
// String uri) {
// this.displayName = displayName;
// this.id = id;
// this.identifier = identifier;
// this.onTourUntil = onTourUntil;
// this.uri = uri;
// }
//
// public String getDisplayName() {
// return displayName;
// }
//
// public String getId() {
// return id;
// }
//
// public List<Identifier> getIdentifier() {
// return identifier;
// }
//
// public String getOnTourUntil() {
// return onTourUntil;
// }
//
// public String getUri() {
// return uri;
// }
// }
|
import java.util.List;
import rx.Observable;
import rx.functions.Action1;
import com.pacoworks.dereference.dependencies.skeleton.IUi;
import com.pacoworks.dereference.model.Artist;
|
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.screens.songkickdetails;
public interface ISongkickDetailsUI extends IUi {
<T> Action1<T> showLoading();
<T> Action1<T> hideLoading();
|
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/skeleton/IUi.java
// public interface IUi {
// Action1<? super Boolean> showOfflineOverlay();
//
// Action1<Throwable> toastError();
//
// Action1<String> toastMessage();
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/model/Artist.java
// @ToString
// public class Artist implements Serializable {
// static final long serialVersionUID = 4653212L;
//
// @SerializedName("displayName")
// private final String displayName;
//
// @SerializedName("id")
// private final String id;
//
// @SerializedName("identifier")
// private final List<Identifier> identifier;
//
// @SerializedName("onTourUntil")
// private final String onTourUntil;
//
// @SerializedName("uri")
// private final String uri;
//
// public Artist(String displayName, String id, List<Identifier> identifier, String onTourUntil,
// String uri) {
// this.displayName = displayName;
// this.id = id;
// this.identifier = identifier;
// this.onTourUntil = onTourUntil;
// this.uri = uri;
// }
//
// public String getDisplayName() {
// return displayName;
// }
//
// public String getId() {
// return id;
// }
//
// public List<Identifier> getIdentifier() {
// return identifier;
// }
//
// public String getOnTourUntil() {
// return onTourUntil;
// }
//
// public String getUri() {
// return uri;
// }
// }
// Path: app/src/main/java/com/pacoworks/dereference/screens/songkickdetails/ISongkickDetailsUI.java
import java.util.List;
import rx.Observable;
import rx.functions.Action1;
import com.pacoworks.dereference.dependencies.skeleton.IUi;
import com.pacoworks.dereference.model.Artist;
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.screens.songkickdetails;
public interface ISongkickDetailsUI extends IUi {
<T> Action1<T> showLoading();
<T> Action1<T> hideLoading();
|
Action1<List<Artist>> swapAdapter();
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/screens/songkickdetails/SongkickDetailsInjectionComponent.java
|
// Path: app/src/whatever/java/com/pacoworks/dereference/ApplicationInjectionComponent.java
// @Singleton
// @Component(modules = {
// ApplicationModule.class, SerializationModule.class, NetworkModule.class
// })
// public interface ApplicationInjectionComponent extends DependencyDescription {
// final class Initializer {
// /* 10 MiB */
// private static final long CACHE_SIZE = 10 * 1024 * 1024;
//
// private Initializer() {
// /* No instances. */
// }
//
// static ApplicationInjectionComponent init(DereferenceApplication app) {
// return DaggerApplicationInjectionComponent
// .builder()
// .applicationModule(new ApplicationModule(app))
// .serializationModule(new SerializationModule())
// .networkModule(
// new NetworkModule(BuildConfig.ENDPOINT, app.getCacheDir(), CACHE_SIZE))
// .build();
// }
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/ActivityInjectionComponent.java
// public interface ActivityInjectionComponent<T extends ZimplBasePresenter> {
// void inject(T presenter);
//
// void inject(ZimplBaseActivity activity);
//
// Activity activity();
//
// ZimplBasePresenter presenter();
//
// Picasso picasso();
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/modules/ActivityModule.java
// @Module
// public class ActivityModule {
// private final Activity activity;
//
// private final Downloader okHttpDownloader;
//
// public ActivityModule(Activity activity, Downloader okHttpDownloader) {
// this.activity = activity;
// this.okHttpDownloader = okHttpDownloader;
// }
//
// @Provides
// @ForActivity
// Activity provideActivity() {
// return activity;
// }
//
// @Provides
// @ForActivity
// Picasso providePicasso() {
// return new Picasso.Builder(activity).downloader(okHttpDownloader).build();
// }
//
// @Provides
// @ForActivity
// Observable<ConnectivityStatus> provideReactiveNetwork() {
// return new ReactiveNetwork().observeConnectivity(activity);
// }
// }
|
import com.pacoworks.dereference.ApplicationInjectionComponent;
import com.pacoworks.dereference.dependencies.ActivityInjectionComponent;
import com.pacoworks.dereference.dependencies.ForActivity;
import com.pacoworks.dereference.dependencies.modules.ActivityModule;
import dagger.Component;
|
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.screens.songkickdetails;
@ForActivity
@Component(dependencies = ApplicationInjectionComponent.class, modules = {
|
// Path: app/src/whatever/java/com/pacoworks/dereference/ApplicationInjectionComponent.java
// @Singleton
// @Component(modules = {
// ApplicationModule.class, SerializationModule.class, NetworkModule.class
// })
// public interface ApplicationInjectionComponent extends DependencyDescription {
// final class Initializer {
// /* 10 MiB */
// private static final long CACHE_SIZE = 10 * 1024 * 1024;
//
// private Initializer() {
// /* No instances. */
// }
//
// static ApplicationInjectionComponent init(DereferenceApplication app) {
// return DaggerApplicationInjectionComponent
// .builder()
// .applicationModule(new ApplicationModule(app))
// .serializationModule(new SerializationModule())
// .networkModule(
// new NetworkModule(BuildConfig.ENDPOINT, app.getCacheDir(), CACHE_SIZE))
// .build();
// }
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/ActivityInjectionComponent.java
// public interface ActivityInjectionComponent<T extends ZimplBasePresenter> {
// void inject(T presenter);
//
// void inject(ZimplBaseActivity activity);
//
// Activity activity();
//
// ZimplBasePresenter presenter();
//
// Picasso picasso();
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/modules/ActivityModule.java
// @Module
// public class ActivityModule {
// private final Activity activity;
//
// private final Downloader okHttpDownloader;
//
// public ActivityModule(Activity activity, Downloader okHttpDownloader) {
// this.activity = activity;
// this.okHttpDownloader = okHttpDownloader;
// }
//
// @Provides
// @ForActivity
// Activity provideActivity() {
// return activity;
// }
//
// @Provides
// @ForActivity
// Picasso providePicasso() {
// return new Picasso.Builder(activity).downloader(okHttpDownloader).build();
// }
//
// @Provides
// @ForActivity
// Observable<ConnectivityStatus> provideReactiveNetwork() {
// return new ReactiveNetwork().observeConnectivity(activity);
// }
// }
// Path: app/src/main/java/com/pacoworks/dereference/screens/songkickdetails/SongkickDetailsInjectionComponent.java
import com.pacoworks.dereference.ApplicationInjectionComponent;
import com.pacoworks.dereference.dependencies.ActivityInjectionComponent;
import com.pacoworks.dereference.dependencies.ForActivity;
import com.pacoworks.dereference.dependencies.modules.ActivityModule;
import dagger.Component;
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.screens.songkickdetails;
@ForActivity
@Component(dependencies = ApplicationInjectionComponent.class, modules = {
|
ActivityModule.class, SongkickDetailsModule.class
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/screens/songkickdetails/SongkickDetailsInjectionComponent.java
|
// Path: app/src/whatever/java/com/pacoworks/dereference/ApplicationInjectionComponent.java
// @Singleton
// @Component(modules = {
// ApplicationModule.class, SerializationModule.class, NetworkModule.class
// })
// public interface ApplicationInjectionComponent extends DependencyDescription {
// final class Initializer {
// /* 10 MiB */
// private static final long CACHE_SIZE = 10 * 1024 * 1024;
//
// private Initializer() {
// /* No instances. */
// }
//
// static ApplicationInjectionComponent init(DereferenceApplication app) {
// return DaggerApplicationInjectionComponent
// .builder()
// .applicationModule(new ApplicationModule(app))
// .serializationModule(new SerializationModule())
// .networkModule(
// new NetworkModule(BuildConfig.ENDPOINT, app.getCacheDir(), CACHE_SIZE))
// .build();
// }
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/ActivityInjectionComponent.java
// public interface ActivityInjectionComponent<T extends ZimplBasePresenter> {
// void inject(T presenter);
//
// void inject(ZimplBaseActivity activity);
//
// Activity activity();
//
// ZimplBasePresenter presenter();
//
// Picasso picasso();
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/modules/ActivityModule.java
// @Module
// public class ActivityModule {
// private final Activity activity;
//
// private final Downloader okHttpDownloader;
//
// public ActivityModule(Activity activity, Downloader okHttpDownloader) {
// this.activity = activity;
// this.okHttpDownloader = okHttpDownloader;
// }
//
// @Provides
// @ForActivity
// Activity provideActivity() {
// return activity;
// }
//
// @Provides
// @ForActivity
// Picasso providePicasso() {
// return new Picasso.Builder(activity).downloader(okHttpDownloader).build();
// }
//
// @Provides
// @ForActivity
// Observable<ConnectivityStatus> provideReactiveNetwork() {
// return new ReactiveNetwork().observeConnectivity(activity);
// }
// }
|
import com.pacoworks.dereference.ApplicationInjectionComponent;
import com.pacoworks.dereference.dependencies.ActivityInjectionComponent;
import com.pacoworks.dereference.dependencies.ForActivity;
import com.pacoworks.dereference.dependencies.modules.ActivityModule;
import dagger.Component;
|
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.screens.songkickdetails;
@ForActivity
@Component(dependencies = ApplicationInjectionComponent.class, modules = {
ActivityModule.class, SongkickDetailsModule.class
})
public interface SongkickDetailsInjectionComponent extends
|
// Path: app/src/whatever/java/com/pacoworks/dereference/ApplicationInjectionComponent.java
// @Singleton
// @Component(modules = {
// ApplicationModule.class, SerializationModule.class, NetworkModule.class
// })
// public interface ApplicationInjectionComponent extends DependencyDescription {
// final class Initializer {
// /* 10 MiB */
// private static final long CACHE_SIZE = 10 * 1024 * 1024;
//
// private Initializer() {
// /* No instances. */
// }
//
// static ApplicationInjectionComponent init(DereferenceApplication app) {
// return DaggerApplicationInjectionComponent
// .builder()
// .applicationModule(new ApplicationModule(app))
// .serializationModule(new SerializationModule())
// .networkModule(
// new NetworkModule(BuildConfig.ENDPOINT, app.getCacheDir(), CACHE_SIZE))
// .build();
// }
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/ActivityInjectionComponent.java
// public interface ActivityInjectionComponent<T extends ZimplBasePresenter> {
// void inject(T presenter);
//
// void inject(ZimplBaseActivity activity);
//
// Activity activity();
//
// ZimplBasePresenter presenter();
//
// Picasso picasso();
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/modules/ActivityModule.java
// @Module
// public class ActivityModule {
// private final Activity activity;
//
// private final Downloader okHttpDownloader;
//
// public ActivityModule(Activity activity, Downloader okHttpDownloader) {
// this.activity = activity;
// this.okHttpDownloader = okHttpDownloader;
// }
//
// @Provides
// @ForActivity
// Activity provideActivity() {
// return activity;
// }
//
// @Provides
// @ForActivity
// Picasso providePicasso() {
// return new Picasso.Builder(activity).downloader(okHttpDownloader).build();
// }
//
// @Provides
// @ForActivity
// Observable<ConnectivityStatus> provideReactiveNetwork() {
// return new ReactiveNetwork().observeConnectivity(activity);
// }
// }
// Path: app/src/main/java/com/pacoworks/dereference/screens/songkickdetails/SongkickDetailsInjectionComponent.java
import com.pacoworks.dereference.ApplicationInjectionComponent;
import com.pacoworks.dereference.dependencies.ActivityInjectionComponent;
import com.pacoworks.dereference.dependencies.ForActivity;
import com.pacoworks.dereference.dependencies.modules.ActivityModule;
import dagger.Component;
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.screens.songkickdetails;
@ForActivity
@Component(dependencies = ApplicationInjectionComponent.class, modules = {
ActivityModule.class, SongkickDetailsModule.class
})
public interface SongkickDetailsInjectionComponent extends
|
ActivityInjectionComponent<SongkickDetailsPresenter> {
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/ui/adapters/ArtistListAdapter.java
|
// Path: app/src/main/java/com/pacoworks/dereference/model/Artist.java
// @ToString
// public class Artist implements Serializable {
// static final long serialVersionUID = 4653212L;
//
// @SerializedName("displayName")
// private final String displayName;
//
// @SerializedName("id")
// private final String id;
//
// @SerializedName("identifier")
// private final List<Identifier> identifier;
//
// @SerializedName("onTourUntil")
// private final String onTourUntil;
//
// @SerializedName("uri")
// private final String uri;
//
// public Artist(String displayName, String id, List<Identifier> identifier, String onTourUntil,
// String uri) {
// this.displayName = displayName;
// this.id = id;
// this.identifier = identifier;
// this.onTourUntil = onTourUntil;
// this.uri = uri;
// }
//
// public String getDisplayName() {
// return displayName;
// }
//
// public String getId() {
// return id;
// }
//
// public List<Identifier> getIdentifier() {
// return identifier;
// }
//
// public String getOnTourUntil() {
// return onTourUntil;
// }
//
// public String getUri() {
// return uri;
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/ui/delegates/ArtistDelegate.java
// public class ArtistDelegate implements AdapterDelegate<List<Artist>> {
// public static final int TYPE = 48984;
//
// SerializedSubject<Artist, Artist> artistClicks = new SerializedSubject<>(
// PublishSubject.<Artist> create());
//
// @Override
// public int getItemViewType() {
// return TYPE;
// }
//
// @Override
// public boolean isForViewType(@NonNull List<Artist> items, int position) {
// return (0 != position || items.size() != 0);
// }
//
// @NonNull
// @Override
// public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent) {
// return new ArtistViewHolder(LayoutInflater.from(parent.getContext()).inflate(
// R.layout.element_artist, parent, false));
// }
//
// @Override
// public void onBindViewHolder(@NonNull List<Artist> items, int position,
// @NonNull RecyclerView.ViewHolder holder) {
// ArtistViewHolder artistViewHolder = (ArtistViewHolder)holder;
// final Artist artist = items.get(position);
// artistViewHolder.name.setText(artist.getDisplayName());
// artistViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// artistClicks.onNext(artist);
// }
// });
// }
//
// public Observable<Artist> getArtistClicks() {
// return artistClicks.asObservable();
// }
//
// static class ArtistViewHolder extends RecyclerView.ViewHolder {
// @Bind(R.id.artist_name_txv)
// TextView name;
//
// public ArtistViewHolder(View itemView) {
// super(itemView);
// ButterKnife.bind(this, itemView);
// }
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/ui/delegates/EmptyDelegate.java
// public class EmptyDelegate<T> implements AdapterDelegate<List<T>> {
// private static final int TYPE = 1916;
//
// @Override
// public int getItemViewType() {
// return TYPE;
// }
//
// @Override
// public boolean isForViewType(@NonNull List<T> items, int i) {
// return i == 0 && items.size() == 0;
// }
//
// @NonNull
// @Override
// public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup) {
// return new EmptyViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(
// R.layout.element_empty, viewGroup, false));
// }
//
// @Override
// public void onBindViewHolder(@NonNull List<T> recordAndReports, int i,
// @NonNull RecyclerView.ViewHolder viewHolder) {
// EmptyViewHolder holder = (EmptyViewHolder)viewHolder;
// }
//
// private class EmptyViewHolder extends RecyclerView.ViewHolder {
// public EmptyViewHolder(View view) {
// super(view);
// }
// }
// }
|
import java.util.ArrayList;
import java.util.List;
import rx.Observable;
import rx.functions.Action1;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;
import com.hannesdorfmann.adapterdelegates.AdapterDelegatesManager;
import com.pacoworks.dereference.model.Artist;
import com.pacoworks.dereference.ui.delegates.ArtistDelegate;
import com.pacoworks.dereference.ui.delegates.EmptyDelegate;
|
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.ui.adapters;
public class ArtistListAdapter extends RecyclerView.Adapter {
private final List<Artist> elementsMap = new ArrayList<>();
private final AdapterDelegatesManager<List<Artist>> delegatesManager = new AdapterDelegatesManager<>();
|
// Path: app/src/main/java/com/pacoworks/dereference/model/Artist.java
// @ToString
// public class Artist implements Serializable {
// static final long serialVersionUID = 4653212L;
//
// @SerializedName("displayName")
// private final String displayName;
//
// @SerializedName("id")
// private final String id;
//
// @SerializedName("identifier")
// private final List<Identifier> identifier;
//
// @SerializedName("onTourUntil")
// private final String onTourUntil;
//
// @SerializedName("uri")
// private final String uri;
//
// public Artist(String displayName, String id, List<Identifier> identifier, String onTourUntil,
// String uri) {
// this.displayName = displayName;
// this.id = id;
// this.identifier = identifier;
// this.onTourUntil = onTourUntil;
// this.uri = uri;
// }
//
// public String getDisplayName() {
// return displayName;
// }
//
// public String getId() {
// return id;
// }
//
// public List<Identifier> getIdentifier() {
// return identifier;
// }
//
// public String getOnTourUntil() {
// return onTourUntil;
// }
//
// public String getUri() {
// return uri;
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/ui/delegates/ArtistDelegate.java
// public class ArtistDelegate implements AdapterDelegate<List<Artist>> {
// public static final int TYPE = 48984;
//
// SerializedSubject<Artist, Artist> artistClicks = new SerializedSubject<>(
// PublishSubject.<Artist> create());
//
// @Override
// public int getItemViewType() {
// return TYPE;
// }
//
// @Override
// public boolean isForViewType(@NonNull List<Artist> items, int position) {
// return (0 != position || items.size() != 0);
// }
//
// @NonNull
// @Override
// public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent) {
// return new ArtistViewHolder(LayoutInflater.from(parent.getContext()).inflate(
// R.layout.element_artist, parent, false));
// }
//
// @Override
// public void onBindViewHolder(@NonNull List<Artist> items, int position,
// @NonNull RecyclerView.ViewHolder holder) {
// ArtistViewHolder artistViewHolder = (ArtistViewHolder)holder;
// final Artist artist = items.get(position);
// artistViewHolder.name.setText(artist.getDisplayName());
// artistViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// artistClicks.onNext(artist);
// }
// });
// }
//
// public Observable<Artist> getArtistClicks() {
// return artistClicks.asObservable();
// }
//
// static class ArtistViewHolder extends RecyclerView.ViewHolder {
// @Bind(R.id.artist_name_txv)
// TextView name;
//
// public ArtistViewHolder(View itemView) {
// super(itemView);
// ButterKnife.bind(this, itemView);
// }
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/ui/delegates/EmptyDelegate.java
// public class EmptyDelegate<T> implements AdapterDelegate<List<T>> {
// private static final int TYPE = 1916;
//
// @Override
// public int getItemViewType() {
// return TYPE;
// }
//
// @Override
// public boolean isForViewType(@NonNull List<T> items, int i) {
// return i == 0 && items.size() == 0;
// }
//
// @NonNull
// @Override
// public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup) {
// return new EmptyViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(
// R.layout.element_empty, viewGroup, false));
// }
//
// @Override
// public void onBindViewHolder(@NonNull List<T> recordAndReports, int i,
// @NonNull RecyclerView.ViewHolder viewHolder) {
// EmptyViewHolder holder = (EmptyViewHolder)viewHolder;
// }
//
// private class EmptyViewHolder extends RecyclerView.ViewHolder {
// public EmptyViewHolder(View view) {
// super(view);
// }
// }
// }
// Path: app/src/main/java/com/pacoworks/dereference/ui/adapters/ArtistListAdapter.java
import java.util.ArrayList;
import java.util.List;
import rx.Observable;
import rx.functions.Action1;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;
import com.hannesdorfmann.adapterdelegates.AdapterDelegatesManager;
import com.pacoworks.dereference.model.Artist;
import com.pacoworks.dereference.ui.delegates.ArtistDelegate;
import com.pacoworks.dereference.ui.delegates.EmptyDelegate;
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.ui.adapters;
public class ArtistListAdapter extends RecyclerView.Adapter {
private final List<Artist> elementsMap = new ArrayList<>();
private final AdapterDelegatesManager<List<Artist>> delegatesManager = new AdapterDelegatesManager<>();
|
private final ArtistDelegate artistDelegate;
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/ui/adapters/ArtistListAdapter.java
|
// Path: app/src/main/java/com/pacoworks/dereference/model/Artist.java
// @ToString
// public class Artist implements Serializable {
// static final long serialVersionUID = 4653212L;
//
// @SerializedName("displayName")
// private final String displayName;
//
// @SerializedName("id")
// private final String id;
//
// @SerializedName("identifier")
// private final List<Identifier> identifier;
//
// @SerializedName("onTourUntil")
// private final String onTourUntil;
//
// @SerializedName("uri")
// private final String uri;
//
// public Artist(String displayName, String id, List<Identifier> identifier, String onTourUntil,
// String uri) {
// this.displayName = displayName;
// this.id = id;
// this.identifier = identifier;
// this.onTourUntil = onTourUntil;
// this.uri = uri;
// }
//
// public String getDisplayName() {
// return displayName;
// }
//
// public String getId() {
// return id;
// }
//
// public List<Identifier> getIdentifier() {
// return identifier;
// }
//
// public String getOnTourUntil() {
// return onTourUntil;
// }
//
// public String getUri() {
// return uri;
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/ui/delegates/ArtistDelegate.java
// public class ArtistDelegate implements AdapterDelegate<List<Artist>> {
// public static final int TYPE = 48984;
//
// SerializedSubject<Artist, Artist> artistClicks = new SerializedSubject<>(
// PublishSubject.<Artist> create());
//
// @Override
// public int getItemViewType() {
// return TYPE;
// }
//
// @Override
// public boolean isForViewType(@NonNull List<Artist> items, int position) {
// return (0 != position || items.size() != 0);
// }
//
// @NonNull
// @Override
// public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent) {
// return new ArtistViewHolder(LayoutInflater.from(parent.getContext()).inflate(
// R.layout.element_artist, parent, false));
// }
//
// @Override
// public void onBindViewHolder(@NonNull List<Artist> items, int position,
// @NonNull RecyclerView.ViewHolder holder) {
// ArtistViewHolder artistViewHolder = (ArtistViewHolder)holder;
// final Artist artist = items.get(position);
// artistViewHolder.name.setText(artist.getDisplayName());
// artistViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// artistClicks.onNext(artist);
// }
// });
// }
//
// public Observable<Artist> getArtistClicks() {
// return artistClicks.asObservable();
// }
//
// static class ArtistViewHolder extends RecyclerView.ViewHolder {
// @Bind(R.id.artist_name_txv)
// TextView name;
//
// public ArtistViewHolder(View itemView) {
// super(itemView);
// ButterKnife.bind(this, itemView);
// }
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/ui/delegates/EmptyDelegate.java
// public class EmptyDelegate<T> implements AdapterDelegate<List<T>> {
// private static final int TYPE = 1916;
//
// @Override
// public int getItemViewType() {
// return TYPE;
// }
//
// @Override
// public boolean isForViewType(@NonNull List<T> items, int i) {
// return i == 0 && items.size() == 0;
// }
//
// @NonNull
// @Override
// public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup) {
// return new EmptyViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(
// R.layout.element_empty, viewGroup, false));
// }
//
// @Override
// public void onBindViewHolder(@NonNull List<T> recordAndReports, int i,
// @NonNull RecyclerView.ViewHolder viewHolder) {
// EmptyViewHolder holder = (EmptyViewHolder)viewHolder;
// }
//
// private class EmptyViewHolder extends RecyclerView.ViewHolder {
// public EmptyViewHolder(View view) {
// super(view);
// }
// }
// }
|
import java.util.ArrayList;
import java.util.List;
import rx.Observable;
import rx.functions.Action1;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;
import com.hannesdorfmann.adapterdelegates.AdapterDelegatesManager;
import com.pacoworks.dereference.model.Artist;
import com.pacoworks.dereference.ui.delegates.ArtistDelegate;
import com.pacoworks.dereference.ui.delegates.EmptyDelegate;
|
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.ui.adapters;
public class ArtistListAdapter extends RecyclerView.Adapter {
private final List<Artist> elementsMap = new ArrayList<>();
private final AdapterDelegatesManager<List<Artist>> delegatesManager = new AdapterDelegatesManager<>();
private final ArtistDelegate artistDelegate;
public ArtistListAdapter() {
artistDelegate = new ArtistDelegate();
delegatesManager.addDelegate(artistDelegate);
|
// Path: app/src/main/java/com/pacoworks/dereference/model/Artist.java
// @ToString
// public class Artist implements Serializable {
// static final long serialVersionUID = 4653212L;
//
// @SerializedName("displayName")
// private final String displayName;
//
// @SerializedName("id")
// private final String id;
//
// @SerializedName("identifier")
// private final List<Identifier> identifier;
//
// @SerializedName("onTourUntil")
// private final String onTourUntil;
//
// @SerializedName("uri")
// private final String uri;
//
// public Artist(String displayName, String id, List<Identifier> identifier, String onTourUntil,
// String uri) {
// this.displayName = displayName;
// this.id = id;
// this.identifier = identifier;
// this.onTourUntil = onTourUntil;
// this.uri = uri;
// }
//
// public String getDisplayName() {
// return displayName;
// }
//
// public String getId() {
// return id;
// }
//
// public List<Identifier> getIdentifier() {
// return identifier;
// }
//
// public String getOnTourUntil() {
// return onTourUntil;
// }
//
// public String getUri() {
// return uri;
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/ui/delegates/ArtistDelegate.java
// public class ArtistDelegate implements AdapterDelegate<List<Artist>> {
// public static final int TYPE = 48984;
//
// SerializedSubject<Artist, Artist> artistClicks = new SerializedSubject<>(
// PublishSubject.<Artist> create());
//
// @Override
// public int getItemViewType() {
// return TYPE;
// }
//
// @Override
// public boolean isForViewType(@NonNull List<Artist> items, int position) {
// return (0 != position || items.size() != 0);
// }
//
// @NonNull
// @Override
// public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent) {
// return new ArtistViewHolder(LayoutInflater.from(parent.getContext()).inflate(
// R.layout.element_artist, parent, false));
// }
//
// @Override
// public void onBindViewHolder(@NonNull List<Artist> items, int position,
// @NonNull RecyclerView.ViewHolder holder) {
// ArtistViewHolder artistViewHolder = (ArtistViewHolder)holder;
// final Artist artist = items.get(position);
// artistViewHolder.name.setText(artist.getDisplayName());
// artistViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// artistClicks.onNext(artist);
// }
// });
// }
//
// public Observable<Artist> getArtistClicks() {
// return artistClicks.asObservable();
// }
//
// static class ArtistViewHolder extends RecyclerView.ViewHolder {
// @Bind(R.id.artist_name_txv)
// TextView name;
//
// public ArtistViewHolder(View itemView) {
// super(itemView);
// ButterKnife.bind(this, itemView);
// }
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/ui/delegates/EmptyDelegate.java
// public class EmptyDelegate<T> implements AdapterDelegate<List<T>> {
// private static final int TYPE = 1916;
//
// @Override
// public int getItemViewType() {
// return TYPE;
// }
//
// @Override
// public boolean isForViewType(@NonNull List<T> items, int i) {
// return i == 0 && items.size() == 0;
// }
//
// @NonNull
// @Override
// public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup) {
// return new EmptyViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(
// R.layout.element_empty, viewGroup, false));
// }
//
// @Override
// public void onBindViewHolder(@NonNull List<T> recordAndReports, int i,
// @NonNull RecyclerView.ViewHolder viewHolder) {
// EmptyViewHolder holder = (EmptyViewHolder)viewHolder;
// }
//
// private class EmptyViewHolder extends RecyclerView.ViewHolder {
// public EmptyViewHolder(View view) {
// super(view);
// }
// }
// }
// Path: app/src/main/java/com/pacoworks/dereference/ui/adapters/ArtistListAdapter.java
import java.util.ArrayList;
import java.util.List;
import rx.Observable;
import rx.functions.Action1;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;
import com.hannesdorfmann.adapterdelegates.AdapterDelegatesManager;
import com.pacoworks.dereference.model.Artist;
import com.pacoworks.dereference.ui.delegates.ArtistDelegate;
import com.pacoworks.dereference.ui.delegates.EmptyDelegate;
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.ui.adapters;
public class ArtistListAdapter extends RecyclerView.Adapter {
private final List<Artist> elementsMap = new ArrayList<>();
private final AdapterDelegatesManager<List<Artist>> delegatesManager = new AdapterDelegatesManager<>();
private final ArtistDelegate artistDelegate;
public ArtistListAdapter() {
artistDelegate = new ArtistDelegate();
delegatesManager.addDelegate(artistDelegate);
|
delegatesManager.addDelegate(new EmptyDelegate<Artist>());
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/dependencies/skeleton/ZimplBaseActivity.java
|
// Path: app/src/whatever/java/com/pacoworks/dereference/ApplicationInjectionComponent.java
// @Singleton
// @Component(modules = {
// ApplicationModule.class, SerializationModule.class, NetworkModule.class
// })
// public interface ApplicationInjectionComponent extends DependencyDescription {
// final class Initializer {
// /* 10 MiB */
// private static final long CACHE_SIZE = 10 * 1024 * 1024;
//
// private Initializer() {
// /* No instances. */
// }
//
// static ApplicationInjectionComponent init(DereferenceApplication app) {
// return DaggerApplicationInjectionComponent
// .builder()
// .applicationModule(new ApplicationModule(app))
// .serializationModule(new SerializationModule())
// .networkModule(
// new NetworkModule(BuildConfig.ENDPOINT, app.getCacheDir(), CACHE_SIZE))
// .build();
// }
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/DereferenceApplication.java
// public class DereferenceApplication extends Application {
// @Inject
// MainInitialiser mainInitialiser;
//
// @Inject
// FlavourInitialiser flavourInitialiser;
// private ApplicationInjectionComponent component;
//
// public static DereferenceApplication get(Context context) {
// return (DereferenceApplication)context.getApplicationContext();
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// buildComponentAndInject();
// }
//
// private void buildComponentAndInject() {
// component = ApplicationInjectionComponent.Initializer.init(this);
// /* Force initialisers to be created */
// component.inject(this);
// }
//
// public ApplicationInjectionComponent component() {
// return component;
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/ActivityInjectionComponent.java
// public interface ActivityInjectionComponent<T extends ZimplBasePresenter> {
// void inject(T presenter);
//
// void inject(ZimplBaseActivity activity);
//
// Activity activity();
//
// ZimplBasePresenter presenter();
//
// Picasso picasso();
// }
|
import javax.inject.Inject;
import lombok.AccessLevel;
import lombok.Getter;
import rx.functions.Action1;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.widget.Toast;
import butterknife.ButterKnife;
import com.pacoworks.dereference.ApplicationInjectionComponent;
import com.pacoworks.dereference.BuildConfig;
import com.pacoworks.dereference.DereferenceApplication;
import com.pacoworks.dereference.dependencies.ActivityInjectionComponent;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.picasso.Picasso;
import io.palaima.debugdrawer.DebugDrawer;
import io.palaima.debugdrawer.log.LogModule;
import io.palaima.debugdrawer.module.BuildModule;
import io.palaima.debugdrawer.module.DeviceModule;
import io.palaima.debugdrawer.module.NetworkModule;
import io.palaima.debugdrawer.module.SettingsModule;
import io.palaima.debugdrawer.okhttp.OkHttpModule;
import io.palaima.debugdrawer.picasso.PicassoModule;
import io.palaima.debugdrawer.scalpel.ScalpelModule;
|
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.dependencies.skeleton;
public abstract class ZimplBaseActivity extends Activity implements IUi {
private static final String PRESENTER_STATE = "presenter_state";
@Inject
Picasso picasso;
@Inject
OkHttpClient okHttpClient;
@Getter(AccessLevel.PROTECTED)
|
// Path: app/src/whatever/java/com/pacoworks/dereference/ApplicationInjectionComponent.java
// @Singleton
// @Component(modules = {
// ApplicationModule.class, SerializationModule.class, NetworkModule.class
// })
// public interface ApplicationInjectionComponent extends DependencyDescription {
// final class Initializer {
// /* 10 MiB */
// private static final long CACHE_SIZE = 10 * 1024 * 1024;
//
// private Initializer() {
// /* No instances. */
// }
//
// static ApplicationInjectionComponent init(DereferenceApplication app) {
// return DaggerApplicationInjectionComponent
// .builder()
// .applicationModule(new ApplicationModule(app))
// .serializationModule(new SerializationModule())
// .networkModule(
// new NetworkModule(BuildConfig.ENDPOINT, app.getCacheDir(), CACHE_SIZE))
// .build();
// }
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/DereferenceApplication.java
// public class DereferenceApplication extends Application {
// @Inject
// MainInitialiser mainInitialiser;
//
// @Inject
// FlavourInitialiser flavourInitialiser;
// private ApplicationInjectionComponent component;
//
// public static DereferenceApplication get(Context context) {
// return (DereferenceApplication)context.getApplicationContext();
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// buildComponentAndInject();
// }
//
// private void buildComponentAndInject() {
// component = ApplicationInjectionComponent.Initializer.init(this);
// /* Force initialisers to be created */
// component.inject(this);
// }
//
// public ApplicationInjectionComponent component() {
// return component;
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/ActivityInjectionComponent.java
// public interface ActivityInjectionComponent<T extends ZimplBasePresenter> {
// void inject(T presenter);
//
// void inject(ZimplBaseActivity activity);
//
// Activity activity();
//
// ZimplBasePresenter presenter();
//
// Picasso picasso();
// }
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/skeleton/ZimplBaseActivity.java
import javax.inject.Inject;
import lombok.AccessLevel;
import lombok.Getter;
import rx.functions.Action1;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.widget.Toast;
import butterknife.ButterKnife;
import com.pacoworks.dereference.ApplicationInjectionComponent;
import com.pacoworks.dereference.BuildConfig;
import com.pacoworks.dereference.DereferenceApplication;
import com.pacoworks.dereference.dependencies.ActivityInjectionComponent;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.picasso.Picasso;
import io.palaima.debugdrawer.DebugDrawer;
import io.palaima.debugdrawer.log.LogModule;
import io.palaima.debugdrawer.module.BuildModule;
import io.palaima.debugdrawer.module.DeviceModule;
import io.palaima.debugdrawer.module.NetworkModule;
import io.palaima.debugdrawer.module.SettingsModule;
import io.palaima.debugdrawer.okhttp.OkHttpModule;
import io.palaima.debugdrawer.picasso.PicassoModule;
import io.palaima.debugdrawer.scalpel.ScalpelModule;
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.dependencies.skeleton;
public abstract class ZimplBaseActivity extends Activity implements IUi {
private static final String PRESENTER_STATE = "presenter_state";
@Inject
Picasso picasso;
@Inject
OkHttpClient okHttpClient;
@Getter(AccessLevel.PROTECTED)
|
private ActivityInjectionComponent injector;
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/dependencies/skeleton/ZimplBaseActivity.java
|
// Path: app/src/whatever/java/com/pacoworks/dereference/ApplicationInjectionComponent.java
// @Singleton
// @Component(modules = {
// ApplicationModule.class, SerializationModule.class, NetworkModule.class
// })
// public interface ApplicationInjectionComponent extends DependencyDescription {
// final class Initializer {
// /* 10 MiB */
// private static final long CACHE_SIZE = 10 * 1024 * 1024;
//
// private Initializer() {
// /* No instances. */
// }
//
// static ApplicationInjectionComponent init(DereferenceApplication app) {
// return DaggerApplicationInjectionComponent
// .builder()
// .applicationModule(new ApplicationModule(app))
// .serializationModule(new SerializationModule())
// .networkModule(
// new NetworkModule(BuildConfig.ENDPOINT, app.getCacheDir(), CACHE_SIZE))
// .build();
// }
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/DereferenceApplication.java
// public class DereferenceApplication extends Application {
// @Inject
// MainInitialiser mainInitialiser;
//
// @Inject
// FlavourInitialiser flavourInitialiser;
// private ApplicationInjectionComponent component;
//
// public static DereferenceApplication get(Context context) {
// return (DereferenceApplication)context.getApplicationContext();
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// buildComponentAndInject();
// }
//
// private void buildComponentAndInject() {
// component = ApplicationInjectionComponent.Initializer.init(this);
// /* Force initialisers to be created */
// component.inject(this);
// }
//
// public ApplicationInjectionComponent component() {
// return component;
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/ActivityInjectionComponent.java
// public interface ActivityInjectionComponent<T extends ZimplBasePresenter> {
// void inject(T presenter);
//
// void inject(ZimplBaseActivity activity);
//
// Activity activity();
//
// ZimplBasePresenter presenter();
//
// Picasso picasso();
// }
|
import javax.inject.Inject;
import lombok.AccessLevel;
import lombok.Getter;
import rx.functions.Action1;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.widget.Toast;
import butterknife.ButterKnife;
import com.pacoworks.dereference.ApplicationInjectionComponent;
import com.pacoworks.dereference.BuildConfig;
import com.pacoworks.dereference.DereferenceApplication;
import com.pacoworks.dereference.dependencies.ActivityInjectionComponent;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.picasso.Picasso;
import io.palaima.debugdrawer.DebugDrawer;
import io.palaima.debugdrawer.log.LogModule;
import io.palaima.debugdrawer.module.BuildModule;
import io.palaima.debugdrawer.module.DeviceModule;
import io.palaima.debugdrawer.module.NetworkModule;
import io.palaima.debugdrawer.module.SettingsModule;
import io.palaima.debugdrawer.okhttp.OkHttpModule;
import io.palaima.debugdrawer.picasso.PicassoModule;
import io.palaima.debugdrawer.scalpel.ScalpelModule;
|
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.dependencies.skeleton;
public abstract class ZimplBaseActivity extends Activity implements IUi {
private static final String PRESENTER_STATE = "presenter_state";
@Inject
Picasso picasso;
@Inject
OkHttpClient okHttpClient;
@Getter(AccessLevel.PROTECTED)
private ActivityInjectionComponent injector;
private ZimplBasePresenter presenter;
private DebugDrawer mDebugDrawer;
@Override
@SuppressWarnings("unchecked")
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
injector = startInjector();
startUi();
restorePresenter(savedInstanceState, injector);
}
@NonNull
private ActivityInjectionComponent startInjector() {
|
// Path: app/src/whatever/java/com/pacoworks/dereference/ApplicationInjectionComponent.java
// @Singleton
// @Component(modules = {
// ApplicationModule.class, SerializationModule.class, NetworkModule.class
// })
// public interface ApplicationInjectionComponent extends DependencyDescription {
// final class Initializer {
// /* 10 MiB */
// private static final long CACHE_SIZE = 10 * 1024 * 1024;
//
// private Initializer() {
// /* No instances. */
// }
//
// static ApplicationInjectionComponent init(DereferenceApplication app) {
// return DaggerApplicationInjectionComponent
// .builder()
// .applicationModule(new ApplicationModule(app))
// .serializationModule(new SerializationModule())
// .networkModule(
// new NetworkModule(BuildConfig.ENDPOINT, app.getCacheDir(), CACHE_SIZE))
// .build();
// }
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/DereferenceApplication.java
// public class DereferenceApplication extends Application {
// @Inject
// MainInitialiser mainInitialiser;
//
// @Inject
// FlavourInitialiser flavourInitialiser;
// private ApplicationInjectionComponent component;
//
// public static DereferenceApplication get(Context context) {
// return (DereferenceApplication)context.getApplicationContext();
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// buildComponentAndInject();
// }
//
// private void buildComponentAndInject() {
// component = ApplicationInjectionComponent.Initializer.init(this);
// /* Force initialisers to be created */
// component.inject(this);
// }
//
// public ApplicationInjectionComponent component() {
// return component;
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/ActivityInjectionComponent.java
// public interface ActivityInjectionComponent<T extends ZimplBasePresenter> {
// void inject(T presenter);
//
// void inject(ZimplBaseActivity activity);
//
// Activity activity();
//
// ZimplBasePresenter presenter();
//
// Picasso picasso();
// }
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/skeleton/ZimplBaseActivity.java
import javax.inject.Inject;
import lombok.AccessLevel;
import lombok.Getter;
import rx.functions.Action1;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.widget.Toast;
import butterknife.ButterKnife;
import com.pacoworks.dereference.ApplicationInjectionComponent;
import com.pacoworks.dereference.BuildConfig;
import com.pacoworks.dereference.DereferenceApplication;
import com.pacoworks.dereference.dependencies.ActivityInjectionComponent;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.picasso.Picasso;
import io.palaima.debugdrawer.DebugDrawer;
import io.palaima.debugdrawer.log.LogModule;
import io.palaima.debugdrawer.module.BuildModule;
import io.palaima.debugdrawer.module.DeviceModule;
import io.palaima.debugdrawer.module.NetworkModule;
import io.palaima.debugdrawer.module.SettingsModule;
import io.palaima.debugdrawer.okhttp.OkHttpModule;
import io.palaima.debugdrawer.picasso.PicassoModule;
import io.palaima.debugdrawer.scalpel.ScalpelModule;
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.dependencies.skeleton;
public abstract class ZimplBaseActivity extends Activity implements IUi {
private static final String PRESENTER_STATE = "presenter_state";
@Inject
Picasso picasso;
@Inject
OkHttpClient okHttpClient;
@Getter(AccessLevel.PROTECTED)
private ActivityInjectionComponent injector;
private ZimplBasePresenter presenter;
private DebugDrawer mDebugDrawer;
@Override
@SuppressWarnings("unchecked")
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
injector = startInjector();
startUi();
restorePresenter(savedInstanceState, injector);
}
@NonNull
private ActivityInjectionComponent startInjector() {
|
final ApplicationInjectionComponent applicationInjectionComponent = DereferenceApplication
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/dependencies/skeleton/ZimplBaseActivity.java
|
// Path: app/src/whatever/java/com/pacoworks/dereference/ApplicationInjectionComponent.java
// @Singleton
// @Component(modules = {
// ApplicationModule.class, SerializationModule.class, NetworkModule.class
// })
// public interface ApplicationInjectionComponent extends DependencyDescription {
// final class Initializer {
// /* 10 MiB */
// private static final long CACHE_SIZE = 10 * 1024 * 1024;
//
// private Initializer() {
// /* No instances. */
// }
//
// static ApplicationInjectionComponent init(DereferenceApplication app) {
// return DaggerApplicationInjectionComponent
// .builder()
// .applicationModule(new ApplicationModule(app))
// .serializationModule(new SerializationModule())
// .networkModule(
// new NetworkModule(BuildConfig.ENDPOINT, app.getCacheDir(), CACHE_SIZE))
// .build();
// }
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/DereferenceApplication.java
// public class DereferenceApplication extends Application {
// @Inject
// MainInitialiser mainInitialiser;
//
// @Inject
// FlavourInitialiser flavourInitialiser;
// private ApplicationInjectionComponent component;
//
// public static DereferenceApplication get(Context context) {
// return (DereferenceApplication)context.getApplicationContext();
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// buildComponentAndInject();
// }
//
// private void buildComponentAndInject() {
// component = ApplicationInjectionComponent.Initializer.init(this);
// /* Force initialisers to be created */
// component.inject(this);
// }
//
// public ApplicationInjectionComponent component() {
// return component;
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/ActivityInjectionComponent.java
// public interface ActivityInjectionComponent<T extends ZimplBasePresenter> {
// void inject(T presenter);
//
// void inject(ZimplBaseActivity activity);
//
// Activity activity();
//
// ZimplBasePresenter presenter();
//
// Picasso picasso();
// }
|
import javax.inject.Inject;
import lombok.AccessLevel;
import lombok.Getter;
import rx.functions.Action1;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.widget.Toast;
import butterknife.ButterKnife;
import com.pacoworks.dereference.ApplicationInjectionComponent;
import com.pacoworks.dereference.BuildConfig;
import com.pacoworks.dereference.DereferenceApplication;
import com.pacoworks.dereference.dependencies.ActivityInjectionComponent;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.picasso.Picasso;
import io.palaima.debugdrawer.DebugDrawer;
import io.palaima.debugdrawer.log.LogModule;
import io.palaima.debugdrawer.module.BuildModule;
import io.palaima.debugdrawer.module.DeviceModule;
import io.palaima.debugdrawer.module.NetworkModule;
import io.palaima.debugdrawer.module.SettingsModule;
import io.palaima.debugdrawer.okhttp.OkHttpModule;
import io.palaima.debugdrawer.picasso.PicassoModule;
import io.palaima.debugdrawer.scalpel.ScalpelModule;
|
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.dependencies.skeleton;
public abstract class ZimplBaseActivity extends Activity implements IUi {
private static final String PRESENTER_STATE = "presenter_state";
@Inject
Picasso picasso;
@Inject
OkHttpClient okHttpClient;
@Getter(AccessLevel.PROTECTED)
private ActivityInjectionComponent injector;
private ZimplBasePresenter presenter;
private DebugDrawer mDebugDrawer;
@Override
@SuppressWarnings("unchecked")
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
injector = startInjector();
startUi();
restorePresenter(savedInstanceState, injector);
}
@NonNull
private ActivityInjectionComponent startInjector() {
|
// Path: app/src/whatever/java/com/pacoworks/dereference/ApplicationInjectionComponent.java
// @Singleton
// @Component(modules = {
// ApplicationModule.class, SerializationModule.class, NetworkModule.class
// })
// public interface ApplicationInjectionComponent extends DependencyDescription {
// final class Initializer {
// /* 10 MiB */
// private static final long CACHE_SIZE = 10 * 1024 * 1024;
//
// private Initializer() {
// /* No instances. */
// }
//
// static ApplicationInjectionComponent init(DereferenceApplication app) {
// return DaggerApplicationInjectionComponent
// .builder()
// .applicationModule(new ApplicationModule(app))
// .serializationModule(new SerializationModule())
// .networkModule(
// new NetworkModule(BuildConfig.ENDPOINT, app.getCacheDir(), CACHE_SIZE))
// .build();
// }
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/DereferenceApplication.java
// public class DereferenceApplication extends Application {
// @Inject
// MainInitialiser mainInitialiser;
//
// @Inject
// FlavourInitialiser flavourInitialiser;
// private ApplicationInjectionComponent component;
//
// public static DereferenceApplication get(Context context) {
// return (DereferenceApplication)context.getApplicationContext();
// }
//
// @Override
// public void onCreate() {
// super.onCreate();
// buildComponentAndInject();
// }
//
// private void buildComponentAndInject() {
// component = ApplicationInjectionComponent.Initializer.init(this);
// /* Force initialisers to be created */
// component.inject(this);
// }
//
// public ApplicationInjectionComponent component() {
// return component;
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/ActivityInjectionComponent.java
// public interface ActivityInjectionComponent<T extends ZimplBasePresenter> {
// void inject(T presenter);
//
// void inject(ZimplBaseActivity activity);
//
// Activity activity();
//
// ZimplBasePresenter presenter();
//
// Picasso picasso();
// }
// Path: app/src/main/java/com/pacoworks/dereference/dependencies/skeleton/ZimplBaseActivity.java
import javax.inject.Inject;
import lombok.AccessLevel;
import lombok.Getter;
import rx.functions.Action1;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.widget.Toast;
import butterknife.ButterKnife;
import com.pacoworks.dereference.ApplicationInjectionComponent;
import com.pacoworks.dereference.BuildConfig;
import com.pacoworks.dereference.DereferenceApplication;
import com.pacoworks.dereference.dependencies.ActivityInjectionComponent;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.picasso.Picasso;
import io.palaima.debugdrawer.DebugDrawer;
import io.palaima.debugdrawer.log.LogModule;
import io.palaima.debugdrawer.module.BuildModule;
import io.palaima.debugdrawer.module.DeviceModule;
import io.palaima.debugdrawer.module.NetworkModule;
import io.palaima.debugdrawer.module.SettingsModule;
import io.palaima.debugdrawer.okhttp.OkHttpModule;
import io.palaima.debugdrawer.picasso.PicassoModule;
import io.palaima.debugdrawer.scalpel.ScalpelModule;
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.dependencies.skeleton;
public abstract class ZimplBaseActivity extends Activity implements IUi {
private static final String PRESENTER_STATE = "presenter_state";
@Inject
Picasso picasso;
@Inject
OkHttpClient okHttpClient;
@Getter(AccessLevel.PROTECTED)
private ActivityInjectionComponent injector;
private ZimplBasePresenter presenter;
private DebugDrawer mDebugDrawer;
@Override
@SuppressWarnings("unchecked")
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
injector = startInjector();
startUi();
restorePresenter(savedInstanceState, injector);
}
@NonNull
private ActivityInjectionComponent startInjector() {
|
final ApplicationInjectionComponent applicationInjectionComponent = DereferenceApplication
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/reactive/RxTuples.java
|
// Path: app/src/main/java/com/pacoworks/dereference/reactive/tuples/Quadriple.java
// @EqualsAndHashCode
// @ToString
// public class Quadriple<T, U, V, X> implements Serializable {
// public final T first;
//
// public final U second;
//
// public final V third;
//
// public final X fourth;
//
// public Quadriple(T first, U second, V third, X fourth) {
// this.first = first;
// this.second = second;
// this.third = third;
// this.fourth = fourth;
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/reactive/tuples/Triple.java
// @EqualsAndHashCode
// @ToString
// public class Triple<T, U, V> implements Serializable {
// public final T first;
//
// public final U second;
//
// public final V third;
//
// public Triple(T first, U second, V third) {
// this.first = first;
// this.second = second;
// this.third = third;
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/reactive/tuples/Tuple.java
// @EqualsAndHashCode
// @ToString
// public class Tuple<T, U> implements Serializable {
// public final T first;
//
// public final U second;
//
// public Tuple(T first, U second) {
// this.first = first;
// this.second = second;
// }
// }
|
import lombok.experimental.UtilityClass;
import rx.functions.Func2;
import com.pacoworks.dereference.reactive.tuples.Quadriple;
import com.pacoworks.dereference.reactive.tuples.Triple;
import com.pacoworks.dereference.reactive.tuples.Tuple;
|
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.reactive;
@UtilityClass
public class RxTuples {
|
// Path: app/src/main/java/com/pacoworks/dereference/reactive/tuples/Quadriple.java
// @EqualsAndHashCode
// @ToString
// public class Quadriple<T, U, V, X> implements Serializable {
// public final T first;
//
// public final U second;
//
// public final V third;
//
// public final X fourth;
//
// public Quadriple(T first, U second, V third, X fourth) {
// this.first = first;
// this.second = second;
// this.third = third;
// this.fourth = fourth;
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/reactive/tuples/Triple.java
// @EqualsAndHashCode
// @ToString
// public class Triple<T, U, V> implements Serializable {
// public final T first;
//
// public final U second;
//
// public final V third;
//
// public Triple(T first, U second, V third) {
// this.first = first;
// this.second = second;
// this.third = third;
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/reactive/tuples/Tuple.java
// @EqualsAndHashCode
// @ToString
// public class Tuple<T, U> implements Serializable {
// public final T first;
//
// public final U second;
//
// public Tuple(T first, U second) {
// this.first = first;
// this.second = second;
// }
// }
// Path: app/src/main/java/com/pacoworks/dereference/reactive/RxTuples.java
import lombok.experimental.UtilityClass;
import rx.functions.Func2;
import com.pacoworks.dereference.reactive.tuples.Quadriple;
import com.pacoworks.dereference.reactive.tuples.Triple;
import com.pacoworks.dereference.reactive.tuples.Tuple;
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.reactive;
@UtilityClass
public class RxTuples {
|
public static <T, U> Func2<T, U, Tuple<T, U>> singleToTuple() {
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/reactive/RxTuples.java
|
// Path: app/src/main/java/com/pacoworks/dereference/reactive/tuples/Quadriple.java
// @EqualsAndHashCode
// @ToString
// public class Quadriple<T, U, V, X> implements Serializable {
// public final T first;
//
// public final U second;
//
// public final V third;
//
// public final X fourth;
//
// public Quadriple(T first, U second, V third, X fourth) {
// this.first = first;
// this.second = second;
// this.third = third;
// this.fourth = fourth;
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/reactive/tuples/Triple.java
// @EqualsAndHashCode
// @ToString
// public class Triple<T, U, V> implements Serializable {
// public final T first;
//
// public final U second;
//
// public final V third;
//
// public Triple(T first, U second, V third) {
// this.first = first;
// this.second = second;
// this.third = third;
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/reactive/tuples/Tuple.java
// @EqualsAndHashCode
// @ToString
// public class Tuple<T, U> implements Serializable {
// public final T first;
//
// public final U second;
//
// public Tuple(T first, U second) {
// this.first = first;
// this.second = second;
// }
// }
|
import lombok.experimental.UtilityClass;
import rx.functions.Func2;
import com.pacoworks.dereference.reactive.tuples.Quadriple;
import com.pacoworks.dereference.reactive.tuples.Triple;
import com.pacoworks.dereference.reactive.tuples.Tuple;
|
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.reactive;
@UtilityClass
public class RxTuples {
public static <T, U> Func2<T, U, Tuple<T, U>> singleToTuple() {
return new Func2<T, U, Tuple<T, U>>() {
@Override
public Tuple<T, U> call(T first, U second) {
return new Tuple<>(first, second);
}
};
}
public static <T, U> Func2<T, U, Tuple<U, T>> singleToTupleInverse() {
return new Func2<T, U, Tuple<U, T>>() {
@Override
public Tuple<U, T> call(T first, U second) {
return new Tuple<>(second, first);
}
};
}
|
// Path: app/src/main/java/com/pacoworks/dereference/reactive/tuples/Quadriple.java
// @EqualsAndHashCode
// @ToString
// public class Quadriple<T, U, V, X> implements Serializable {
// public final T first;
//
// public final U second;
//
// public final V third;
//
// public final X fourth;
//
// public Quadriple(T first, U second, V third, X fourth) {
// this.first = first;
// this.second = second;
// this.third = third;
// this.fourth = fourth;
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/reactive/tuples/Triple.java
// @EqualsAndHashCode
// @ToString
// public class Triple<T, U, V> implements Serializable {
// public final T first;
//
// public final U second;
//
// public final V third;
//
// public Triple(T first, U second, V third) {
// this.first = first;
// this.second = second;
// this.third = third;
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/reactive/tuples/Tuple.java
// @EqualsAndHashCode
// @ToString
// public class Tuple<T, U> implements Serializable {
// public final T first;
//
// public final U second;
//
// public Tuple(T first, U second) {
// this.first = first;
// this.second = second;
// }
// }
// Path: app/src/main/java/com/pacoworks/dereference/reactive/RxTuples.java
import lombok.experimental.UtilityClass;
import rx.functions.Func2;
import com.pacoworks.dereference.reactive.tuples.Quadriple;
import com.pacoworks.dereference.reactive.tuples.Triple;
import com.pacoworks.dereference.reactive.tuples.Tuple;
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.reactive;
@UtilityClass
public class RxTuples {
public static <T, U> Func2<T, U, Tuple<T, U>> singleToTuple() {
return new Func2<T, U, Tuple<T, U>>() {
@Override
public Tuple<T, U> call(T first, U second) {
return new Tuple<>(first, second);
}
};
}
public static <T, U> Func2<T, U, Tuple<U, T>> singleToTupleInverse() {
return new Func2<T, U, Tuple<U, T>>() {
@Override
public Tuple<U, T> call(T first, U second) {
return new Tuple<>(second, first);
}
};
}
|
public static <T, U, V> Func2<T, Tuple<U, V>, Triple<T, U, V>> singleToTriple() {
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/reactive/RxTuples.java
|
// Path: app/src/main/java/com/pacoworks/dereference/reactive/tuples/Quadriple.java
// @EqualsAndHashCode
// @ToString
// public class Quadriple<T, U, V, X> implements Serializable {
// public final T first;
//
// public final U second;
//
// public final V third;
//
// public final X fourth;
//
// public Quadriple(T first, U second, V third, X fourth) {
// this.first = first;
// this.second = second;
// this.third = third;
// this.fourth = fourth;
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/reactive/tuples/Triple.java
// @EqualsAndHashCode
// @ToString
// public class Triple<T, U, V> implements Serializable {
// public final T first;
//
// public final U second;
//
// public final V third;
//
// public Triple(T first, U second, V third) {
// this.first = first;
// this.second = second;
// this.third = third;
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/reactive/tuples/Tuple.java
// @EqualsAndHashCode
// @ToString
// public class Tuple<T, U> implements Serializable {
// public final T first;
//
// public final U second;
//
// public Tuple(T first, U second) {
// this.first = first;
// this.second = second;
// }
// }
|
import lombok.experimental.UtilityClass;
import rx.functions.Func2;
import com.pacoworks.dereference.reactive.tuples.Quadriple;
import com.pacoworks.dereference.reactive.tuples.Triple;
import com.pacoworks.dereference.reactive.tuples.Tuple;
|
};
}
public static <T, U> Func2<T, U, Tuple<U, T>> singleToTupleInverse() {
return new Func2<T, U, Tuple<U, T>>() {
@Override
public Tuple<U, T> call(T first, U second) {
return new Tuple<>(second, first);
}
};
}
public static <T, U, V> Func2<T, Tuple<U, V>, Triple<T, U, V>> singleToTriple() {
return new Func2<T, Tuple<U, V>, Triple<T, U, V>>() {
@Override
public Triple<T, U, V> call(T first, Tuple<U, V> second) {
return new Triple<>(first, second.first, second.second);
}
};
}
public static <T, U, V> Func2<Tuple<T, U>, V, Triple<T, U, V>> tupleToTriple() {
return new Func2<Tuple<T, U>, V, Triple<T, U, V>>() {
@Override
public Triple<T, U, V> call(Tuple<T, U> first, V second) {
return new Triple<>(first.first, first.second, second);
}
};
}
|
// Path: app/src/main/java/com/pacoworks/dereference/reactive/tuples/Quadriple.java
// @EqualsAndHashCode
// @ToString
// public class Quadriple<T, U, V, X> implements Serializable {
// public final T first;
//
// public final U second;
//
// public final V third;
//
// public final X fourth;
//
// public Quadriple(T first, U second, V third, X fourth) {
// this.first = first;
// this.second = second;
// this.third = third;
// this.fourth = fourth;
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/reactive/tuples/Triple.java
// @EqualsAndHashCode
// @ToString
// public class Triple<T, U, V> implements Serializable {
// public final T first;
//
// public final U second;
//
// public final V third;
//
// public Triple(T first, U second, V third) {
// this.first = first;
// this.second = second;
// this.third = third;
// }
// }
//
// Path: app/src/main/java/com/pacoworks/dereference/reactive/tuples/Tuple.java
// @EqualsAndHashCode
// @ToString
// public class Tuple<T, U> implements Serializable {
// public final T first;
//
// public final U second;
//
// public Tuple(T first, U second) {
// this.first = first;
// this.second = second;
// }
// }
// Path: app/src/main/java/com/pacoworks/dereference/reactive/RxTuples.java
import lombok.experimental.UtilityClass;
import rx.functions.Func2;
import com.pacoworks.dereference.reactive.tuples.Quadriple;
import com.pacoworks.dereference.reactive.tuples.Triple;
import com.pacoworks.dereference.reactive.tuples.Tuple;
};
}
public static <T, U> Func2<T, U, Tuple<U, T>> singleToTupleInverse() {
return new Func2<T, U, Tuple<U, T>>() {
@Override
public Tuple<U, T> call(T first, U second) {
return new Tuple<>(second, first);
}
};
}
public static <T, U, V> Func2<T, Tuple<U, V>, Triple<T, U, V>> singleToTriple() {
return new Func2<T, Tuple<U, V>, Triple<T, U, V>>() {
@Override
public Triple<T, U, V> call(T first, Tuple<U, V> second) {
return new Triple<>(first, second.first, second.second);
}
};
}
public static <T, U, V> Func2<Tuple<T, U>, V, Triple<T, U, V>> tupleToTriple() {
return new Func2<Tuple<T, U>, V, Triple<T, U, V>>() {
@Override
public Triple<T, U, V> call(Tuple<T, U> first, V second) {
return new Triple<>(first.first, first.second, second);
}
};
}
|
public static <T, U, V, X> Func2<T, Triple<U, V, X>, Quadriple<T, U, V, X>> singleToQuadruple() {
|
pakoito/SongkickInterview
|
app/src/main/java/com/pacoworks/dereference/network/SongkickApi.java
|
// Path: app/src/main/java/com/pacoworks/dereference/model/SearchResult.java
// @ToString
// public class SearchResult {
// @SerializedName("resultsPage")
// private final ResultsPage resultsPage;
//
// public SearchResult(ResultsPage resultsPage) {
// this.resultsPage = resultsPage;
// }
//
// public ResultsPage getResultsPage() {
// return resultsPage;
// }
// }
|
import retrofit.http.GET;
import retrofit.http.Path;
import retrofit.http.Query;
import rx.Observable;
import com.pacoworks.dereference.model.SearchResult;
|
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.network;
public interface SongkickApi {
@GET("search/artists.json")
|
// Path: app/src/main/java/com/pacoworks/dereference/model/SearchResult.java
// @ToString
// public class SearchResult {
// @SerializedName("resultsPage")
// private final ResultsPage resultsPage;
//
// public SearchResult(ResultsPage resultsPage) {
// this.resultsPage = resultsPage;
// }
//
// public ResultsPage getResultsPage() {
// return resultsPage;
// }
// }
// Path: app/src/main/java/com/pacoworks/dereference/network/SongkickApi.java
import retrofit.http.GET;
import retrofit.http.Path;
import retrofit.http.Query;
import rx.Observable;
import com.pacoworks.dereference.model.SearchResult;
/*
* Copyright (c) pakoito 2015
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.pacoworks.dereference.network;
public interface SongkickApi {
@GET("search/artists.json")
|
Observable<SearchResult> getSearchResult(@Query("apikey") String apikey,
|
philliphsu/ClockPlus
|
app/src/main/java/com/philliphsu/clock2/dialogs/RingtonePickerDialog.java
|
// Path: app/src/main/java/com/philliphsu/clock2/ringtone/playback/RingtoneLoop.java
// public final class RingtoneLoop {
//
// private final Context mContext;
// private final AudioManager mAudioManager;
// private final Uri mUri;
//
// private MediaPlayer mMediaPlayer;
//
// public RingtoneLoop(Context context, Uri uri) {
// mContext = context;
// mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
// mUri = uri;
// }
//
// public void play() {
// try {
// mMediaPlayer = new MediaPlayer();
// mMediaPlayer.setDataSource(mContext, mUri);
// if (mAudioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
// // "Must call this method before prepare() or prepareAsync() in order
// // for the target stream type to become effective thereafter."
// mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
// mMediaPlayer.setLooping(true);
// // There is prepare() and prepareAsync().
// // "For files, it is OK to call prepare(), which blocks until
// // MediaPlayer is ready for playback."
// mMediaPlayer.prepare();
// mMediaPlayer.start();
// }
// } catch (SecurityException | IOException e) {
// destroyLocalPlayer();
// }
// }
//
// public void stop() {
// if (mMediaPlayer != null) {
// destroyLocalPlayer();
// }
// }
//
// private void destroyLocalPlayer() {
// if (mMediaPlayer != null) {
// mMediaPlayer.reset();
// mMediaPlayer.release();
// mMediaPlayer = null;
// }
// }
//
// }
|
import android.content.DialogInterface;
import android.database.Cursor;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import com.philliphsu.clock2.R;
import com.philliphsu.clock2.ringtone.playback.RingtoneLoop;
|
/*
* Copyright 2017 Phillip Hsu
*
* This file is part of ClockPlus.
*
* ClockPlus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ClockPlus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ClockPlus. If not, see <http://www.gnu.org/licenses/>.
*/
package com.philliphsu.clock2.dialogs;
/**
* Created by Phillip Hsu on 9/3/2016.
* <p></p>
* An alternative to the system's ringtone picker dialog. The differences are:
* (1) this dialog matches the current theme,
* (2) the selected ringtone URI is delivered via the {@link OnRingtoneSelectedListener
* OnRingtoneSelectedListener} callback.
* <p></p>
* TODO: If a ringtone was playing and the configuration changes, the ringtone is destroyed.
* Restore the playing ringtone (seamlessly, without the stutter that comes from restarting).
* Setting setRetainInstance(true) in onCreate() made our app crash (error said attempted to
* access closed Cursor).
* We might need to play the ringtone from a Service instead, so we won't have to worry about
* the ringtone being destroyed on rotation.
*/
public class RingtonePickerDialog extends BaseAlertDialogFragment {
private static final String TAG = "RingtonePickerDialog";
private static final String KEY_RINGTONE_URI = "key_ringtone_uri";
private RingtoneManager mRingtoneManager;
private OnRingtoneSelectedListener mOnRingtoneSelectedListener;
private Uri mRingtoneUri;
|
// Path: app/src/main/java/com/philliphsu/clock2/ringtone/playback/RingtoneLoop.java
// public final class RingtoneLoop {
//
// private final Context mContext;
// private final AudioManager mAudioManager;
// private final Uri mUri;
//
// private MediaPlayer mMediaPlayer;
//
// public RingtoneLoop(Context context, Uri uri) {
// mContext = context;
// mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
// mUri = uri;
// }
//
// public void play() {
// try {
// mMediaPlayer = new MediaPlayer();
// mMediaPlayer.setDataSource(mContext, mUri);
// if (mAudioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
// // "Must call this method before prepare() or prepareAsync() in order
// // for the target stream type to become effective thereafter."
// mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
// mMediaPlayer.setLooping(true);
// // There is prepare() and prepareAsync().
// // "For files, it is OK to call prepare(), which blocks until
// // MediaPlayer is ready for playback."
// mMediaPlayer.prepare();
// mMediaPlayer.start();
// }
// } catch (SecurityException | IOException e) {
// destroyLocalPlayer();
// }
// }
//
// public void stop() {
// if (mMediaPlayer != null) {
// destroyLocalPlayer();
// }
// }
//
// private void destroyLocalPlayer() {
// if (mMediaPlayer != null) {
// mMediaPlayer.reset();
// mMediaPlayer.release();
// mMediaPlayer = null;
// }
// }
//
// }
// Path: app/src/main/java/com/philliphsu/clock2/dialogs/RingtonePickerDialog.java
import android.content.DialogInterface;
import android.database.Cursor;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import com.philliphsu.clock2.R;
import com.philliphsu.clock2.ringtone.playback.RingtoneLoop;
/*
* Copyright 2017 Phillip Hsu
*
* This file is part of ClockPlus.
*
* ClockPlus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ClockPlus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ClockPlus. If not, see <http://www.gnu.org/licenses/>.
*/
package com.philliphsu.clock2.dialogs;
/**
* Created by Phillip Hsu on 9/3/2016.
* <p></p>
* An alternative to the system's ringtone picker dialog. The differences are:
* (1) this dialog matches the current theme,
* (2) the selected ringtone URI is delivered via the {@link OnRingtoneSelectedListener
* OnRingtoneSelectedListener} callback.
* <p></p>
* TODO: If a ringtone was playing and the configuration changes, the ringtone is destroyed.
* Restore the playing ringtone (seamlessly, without the stutter that comes from restarting).
* Setting setRetainInstance(true) in onCreate() made our app crash (error said attempted to
* access closed Cursor).
* We might need to play the ringtone from a Service instead, so we won't have to worry about
* the ringtone being destroyed on rotation.
*/
public class RingtonePickerDialog extends BaseAlertDialogFragment {
private static final String TAG = "RingtonePickerDialog";
private static final String KEY_RINGTONE_URI = "key_ringtone_uri";
private RingtoneManager mRingtoneManager;
private OnRingtoneSelectedListener mOnRingtoneSelectedListener;
private Uri mRingtoneUri;
|
private RingtoneLoop mRingtone;
|
philliphsu/ClockPlus
|
app/src/main/java/com/philliphsu/clock2/timers/TimerController.java
|
// Path: app/src/main/java/com/philliphsu/clock2/timers/data/AsyncTimersTableUpdateHandler.java
// public final class AsyncTimersTableUpdateHandler extends AsyncDatabaseTableUpdateHandler<Timer, TimersTableManager> {
// private static final String TAG = "TimersTableUpdater"; // TAG max 23 chars
//
// public AsyncTimersTableUpdateHandler(Context context, ScrollHandler scrollHandler) {
// super(context, scrollHandler);
// }
//
// @Override
// protected TimersTableManager onCreateTableManager(Context context) {
// return new TimersTableManager(context);
// }
//
// @Override
// protected void onPostAsyncDelete(Integer result, Timer timer) {
// cancelAlarm(timer, true);
// }
//
// @Override
// protected void onPostAsyncInsert(Long result, Timer timer) {
// if (timer.isRunning()) {
// scheduleAlarm(timer);
// }
// }
//
// @Override
// protected void onPostAsyncUpdate(Long result, Timer timer) {
// Log.d(TAG, "onPostAsyncUpdate, timer = " + timer);
// if (timer.isRunning()) {
// // We don't need to cancel the previous alarm, because this one
// // will remove and replace it.
// scheduleAlarm(timer);
// } else {
// boolean removeNotification = !timer.hasStarted();
// cancelAlarm(timer, removeNotification);
// if (!removeNotification) {
// // Post a new notification to reflect the paused state of the timer
// TimerNotificationService.showNotification(getContext(), timer);
// }
// }
// }
//
// // TODO: Consider changing to just a long id param
// private PendingIntent createTimesUpIntent(Timer timer) {
// Intent intent = new Intent(getContext(), TimesUpActivity.class);
// intent.putExtra(TimesUpActivity.EXTRA_RINGING_OBJECT, ParcelableUtil.marshall(timer));
// // There's no point to determining whether to retrieve a previous instance, because
// // we chose to ignore it since we had issues with NPEs. TODO: Perhaps these issues
// // were caused by you using the same reference variable for every Intent/PI that
// // needed to be recreated, and you reassigning the reference each time you were done with
// // one of them, which leaves the one before unreferenced and hence eligible for GC.
// return PendingIntent.getActivity(getContext(), timer.getIntId(), intent, PendingIntent.FLAG_CANCEL_CURRENT);
// }
//
// private void scheduleAlarm(Timer timer) {
// AlarmManager am = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE);
// am.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, timer.endTime(), createTimesUpIntent(timer));
// TimerNotificationService.showNotification(getContext(), timer);
// }
//
// private void cancelAlarm(Timer timer, boolean removeNotification) {
// // Cancel the alarm scheduled. If one was never scheduled, does nothing.
// AlarmManager am = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE);
// PendingIntent pi = createTimesUpIntent(timer);
// // Now can't be null
// am.cancel(pi);
// pi.cancel();
// if (removeNotification) {
// TimerNotificationService.cancelNotification(getContext(), timer.getId());
// }
// // Won't do anything if not actually started
// // This was actually a problem for successive Timers. We actually don't need to
// // manually stop the service in many cases. See usages of TimerController.stop().
// // getContext().stopService(new Intent(getContext(), TimerRingtoneService.class));
// // TODO: Do we need to finish TimesUpActivity?
// }
// }
|
import android.util.Log;
import com.philliphsu.clock2.timers.data.AsyncTimersTableUpdateHandler;
|
/*
* Copyright 2017 Phillip Hsu
*
* This file is part of ClockPlus.
*
* ClockPlus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ClockPlus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ClockPlus. If not, see <http://www.gnu.org/licenses/>.
*/
package com.philliphsu.clock2.timers;
/**
* Created by Phillip Hsu on 7/27/2016.
*/
public class TimerController {
private static final String TAG = "TimerController";
private final Timer mTimer;
|
// Path: app/src/main/java/com/philliphsu/clock2/timers/data/AsyncTimersTableUpdateHandler.java
// public final class AsyncTimersTableUpdateHandler extends AsyncDatabaseTableUpdateHandler<Timer, TimersTableManager> {
// private static final String TAG = "TimersTableUpdater"; // TAG max 23 chars
//
// public AsyncTimersTableUpdateHandler(Context context, ScrollHandler scrollHandler) {
// super(context, scrollHandler);
// }
//
// @Override
// protected TimersTableManager onCreateTableManager(Context context) {
// return new TimersTableManager(context);
// }
//
// @Override
// protected void onPostAsyncDelete(Integer result, Timer timer) {
// cancelAlarm(timer, true);
// }
//
// @Override
// protected void onPostAsyncInsert(Long result, Timer timer) {
// if (timer.isRunning()) {
// scheduleAlarm(timer);
// }
// }
//
// @Override
// protected void onPostAsyncUpdate(Long result, Timer timer) {
// Log.d(TAG, "onPostAsyncUpdate, timer = " + timer);
// if (timer.isRunning()) {
// // We don't need to cancel the previous alarm, because this one
// // will remove and replace it.
// scheduleAlarm(timer);
// } else {
// boolean removeNotification = !timer.hasStarted();
// cancelAlarm(timer, removeNotification);
// if (!removeNotification) {
// // Post a new notification to reflect the paused state of the timer
// TimerNotificationService.showNotification(getContext(), timer);
// }
// }
// }
//
// // TODO: Consider changing to just a long id param
// private PendingIntent createTimesUpIntent(Timer timer) {
// Intent intent = new Intent(getContext(), TimesUpActivity.class);
// intent.putExtra(TimesUpActivity.EXTRA_RINGING_OBJECT, ParcelableUtil.marshall(timer));
// // There's no point to determining whether to retrieve a previous instance, because
// // we chose to ignore it since we had issues with NPEs. TODO: Perhaps these issues
// // were caused by you using the same reference variable for every Intent/PI that
// // needed to be recreated, and you reassigning the reference each time you were done with
// // one of them, which leaves the one before unreferenced and hence eligible for GC.
// return PendingIntent.getActivity(getContext(), timer.getIntId(), intent, PendingIntent.FLAG_CANCEL_CURRENT);
// }
//
// private void scheduleAlarm(Timer timer) {
// AlarmManager am = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE);
// am.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, timer.endTime(), createTimesUpIntent(timer));
// TimerNotificationService.showNotification(getContext(), timer);
// }
//
// private void cancelAlarm(Timer timer, boolean removeNotification) {
// // Cancel the alarm scheduled. If one was never scheduled, does nothing.
// AlarmManager am = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE);
// PendingIntent pi = createTimesUpIntent(timer);
// // Now can't be null
// am.cancel(pi);
// pi.cancel();
// if (removeNotification) {
// TimerNotificationService.cancelNotification(getContext(), timer.getId());
// }
// // Won't do anything if not actually started
// // This was actually a problem for successive Timers. We actually don't need to
// // manually stop the service in many cases. See usages of TimerController.stop().
// // getContext().stopService(new Intent(getContext(), TimerRingtoneService.class));
// // TODO: Do we need to finish TimesUpActivity?
// }
// }
// Path: app/src/main/java/com/philliphsu/clock2/timers/TimerController.java
import android.util.Log;
import com.philliphsu.clock2.timers.data.AsyncTimersTableUpdateHandler;
/*
* Copyright 2017 Phillip Hsu
*
* This file is part of ClockPlus.
*
* ClockPlus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ClockPlus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ClockPlus. If not, see <http://www.gnu.org/licenses/>.
*/
package com.philliphsu.clock2.timers;
/**
* Created by Phillip Hsu on 7/27/2016.
*/
public class TimerController {
private static final String TAG = "TimerController";
private final Timer mTimer;
|
private final AsyncTimersTableUpdateHandler mUpdateHandler;
|
philliphsu/ClockPlus
|
app/src/main/java/com/philliphsu/clock2/settings/ThemedRingtonePreference.java
|
// Path: app/src/main/java/com/philliphsu/clock2/dialogs/RingtonePickerDialog.java
// public class RingtonePickerDialog extends BaseAlertDialogFragment {
// private static final String TAG = "RingtonePickerDialog";
// private static final String KEY_RINGTONE_URI = "key_ringtone_uri";
//
// private RingtoneManager mRingtoneManager;
// private OnRingtoneSelectedListener mOnRingtoneSelectedListener;
// private Uri mRingtoneUri;
// private RingtoneLoop mRingtone;
//
// public interface OnRingtoneSelectedListener {
// void onRingtoneSelected(Uri ringtoneUri);
// }
//
// /**
// * @param ringtoneUri the URI of the ringtone to show as initially selected
// */
// public static RingtonePickerDialog newInstance(OnRingtoneSelectedListener l, Uri ringtoneUri) {
// RingtonePickerDialog dialog = new RingtonePickerDialog();
// dialog.mOnRingtoneSelectedListener = l;
// dialog.mRingtoneUri = ringtoneUri;
// return dialog;
// }
//
// @Override
// public void onCreate(@Nullable Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// if (savedInstanceState != null) {
// mRingtoneUri = savedInstanceState.getParcelable(KEY_RINGTONE_URI);
// }
// mRingtoneManager = new RingtoneManager(getActivity());
// mRingtoneManager.setType(RingtoneManager.TYPE_ALARM);
// }
//
// @Override
// protected AlertDialog createFrom(AlertDialog.Builder builder) {
// // TODO: We set the READ_EXTERNAL_STORAGE permission. Verify that this includes the user's
// // custom ringtone files.
// Cursor cursor = mRingtoneManager.getCursor();
// int checkedItem = mRingtoneManager.getRingtonePosition(mRingtoneUri);
// String labelColumn = cursor.getColumnName(RingtoneManager.TITLE_COLUMN_INDEX);
//
// builder.setTitle(R.string.ringtones)
// .setSingleChoiceItems(cursor, checkedItem, labelColumn, new DialogInterface.OnClickListener() {
// @Override
// public void onClick(DialogInterface dialog, int which) {
// if (mRingtone != null) {
// destroyLocalPlayer();
// }
// // Here, 'which' param refers to the position of the item clicked.
// mRingtoneUri = mRingtoneManager.getRingtoneUri(which);
// mRingtone = new RingtoneLoop(getActivity(), mRingtoneUri);
// mRingtone.play();
// }
// });
// return super.createFrom(builder);
// }
//
// @Override
// public void onDismiss(DialogInterface dialog) {
// super.onDismiss(dialog);
// destroyLocalPlayer();
// }
//
// @Override
// public void onSaveInstanceState(Bundle outState) {
// super.onSaveInstanceState(outState);
// outState.putParcelable(KEY_RINGTONE_URI, mRingtoneUri);
// }
//
// @Override
// protected void onOk() {
// if (mOnRingtoneSelectedListener != null) {
// // Here, 'which' param refers to the position of the item clicked.
// mOnRingtoneSelectedListener.onRingtoneSelected(mRingtoneUri);
// }
// dismiss();
// }
//
// public void setOnRingtoneSelectedListener(OnRingtoneSelectedListener onRingtoneSelectedListener) {
// mOnRingtoneSelectedListener = onRingtoneSelectedListener;
// }
//
// private void destroyLocalPlayer() {
// if (mRingtone != null) {
// mRingtone.stop();
// mRingtone = null;
// }
// }
// }
//
// Path: app/src/main/java/com/philliphsu/clock2/dialogs/RingtonePickerDialogController.java
// public class RingtonePickerDialogController extends DialogFragmentController<RingtonePickerDialog> {
// private static final String TAG = "RingtonePickerCtrller";
//
// private final RingtonePickerDialog.OnRingtoneSelectedListener mListener;
//
// public RingtonePickerDialogController(FragmentManager fragmentManager, RingtonePickerDialog.OnRingtoneSelectedListener l) {
// super(fragmentManager);
// mListener = l;
// }
//
// public void show(Uri initialUri, String tag) {
// RingtonePickerDialog dialog = RingtonePickerDialog.newInstance(mListener, initialUri);
// show(dialog, tag);
// }
//
// @Override
// public void tryRestoreCallback(String tag) {
// RingtonePickerDialog dialog = findDialog(tag);
// if (dialog != null) {
// Log.i(TAG, "Restoring on ringtone selected callback");
// dialog.setOnRingtoneSelectedListener(mListener);
// }
// }
// }
|
import com.philliphsu.clock2.dialogs.RingtonePickerDialog;
import com.philliphsu.clock2.dialogs.RingtonePickerDialogController;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.net.Uri;
import android.os.Parcelable;
import android.preference.RingtonePreference;
import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.util.AttributeSet;
|
/*
* Copyright 2017 Phillip Hsu
*
* This file is part of ClockPlus.
*
* ClockPlus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ClockPlus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ClockPlus. If not, see <http://www.gnu.org/licenses/>.
*/
package com.philliphsu.clock2.settings;
/**
* Created by Phillip Hsu on 9/20/2016.
*
* <p>A modified version of the framework's {@link android.preference.RingtonePreference} that
* uses our {@link RingtonePickerDialog} instead of the system's ringtone picker.</p>
*/
public class ThemedRingtonePreference extends RingtonePreference
implements RingtonePickerDialog.OnRingtoneSelectedListener {
private static final String TAG = "ThemedRingtonePreference";
|
// Path: app/src/main/java/com/philliphsu/clock2/dialogs/RingtonePickerDialog.java
// public class RingtonePickerDialog extends BaseAlertDialogFragment {
// private static final String TAG = "RingtonePickerDialog";
// private static final String KEY_RINGTONE_URI = "key_ringtone_uri";
//
// private RingtoneManager mRingtoneManager;
// private OnRingtoneSelectedListener mOnRingtoneSelectedListener;
// private Uri mRingtoneUri;
// private RingtoneLoop mRingtone;
//
// public interface OnRingtoneSelectedListener {
// void onRingtoneSelected(Uri ringtoneUri);
// }
//
// /**
// * @param ringtoneUri the URI of the ringtone to show as initially selected
// */
// public static RingtonePickerDialog newInstance(OnRingtoneSelectedListener l, Uri ringtoneUri) {
// RingtonePickerDialog dialog = new RingtonePickerDialog();
// dialog.mOnRingtoneSelectedListener = l;
// dialog.mRingtoneUri = ringtoneUri;
// return dialog;
// }
//
// @Override
// public void onCreate(@Nullable Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// if (savedInstanceState != null) {
// mRingtoneUri = savedInstanceState.getParcelable(KEY_RINGTONE_URI);
// }
// mRingtoneManager = new RingtoneManager(getActivity());
// mRingtoneManager.setType(RingtoneManager.TYPE_ALARM);
// }
//
// @Override
// protected AlertDialog createFrom(AlertDialog.Builder builder) {
// // TODO: We set the READ_EXTERNAL_STORAGE permission. Verify that this includes the user's
// // custom ringtone files.
// Cursor cursor = mRingtoneManager.getCursor();
// int checkedItem = mRingtoneManager.getRingtonePosition(mRingtoneUri);
// String labelColumn = cursor.getColumnName(RingtoneManager.TITLE_COLUMN_INDEX);
//
// builder.setTitle(R.string.ringtones)
// .setSingleChoiceItems(cursor, checkedItem, labelColumn, new DialogInterface.OnClickListener() {
// @Override
// public void onClick(DialogInterface dialog, int which) {
// if (mRingtone != null) {
// destroyLocalPlayer();
// }
// // Here, 'which' param refers to the position of the item clicked.
// mRingtoneUri = mRingtoneManager.getRingtoneUri(which);
// mRingtone = new RingtoneLoop(getActivity(), mRingtoneUri);
// mRingtone.play();
// }
// });
// return super.createFrom(builder);
// }
//
// @Override
// public void onDismiss(DialogInterface dialog) {
// super.onDismiss(dialog);
// destroyLocalPlayer();
// }
//
// @Override
// public void onSaveInstanceState(Bundle outState) {
// super.onSaveInstanceState(outState);
// outState.putParcelable(KEY_RINGTONE_URI, mRingtoneUri);
// }
//
// @Override
// protected void onOk() {
// if (mOnRingtoneSelectedListener != null) {
// // Here, 'which' param refers to the position of the item clicked.
// mOnRingtoneSelectedListener.onRingtoneSelected(mRingtoneUri);
// }
// dismiss();
// }
//
// public void setOnRingtoneSelectedListener(OnRingtoneSelectedListener onRingtoneSelectedListener) {
// mOnRingtoneSelectedListener = onRingtoneSelectedListener;
// }
//
// private void destroyLocalPlayer() {
// if (mRingtone != null) {
// mRingtone.stop();
// mRingtone = null;
// }
// }
// }
//
// Path: app/src/main/java/com/philliphsu/clock2/dialogs/RingtonePickerDialogController.java
// public class RingtonePickerDialogController extends DialogFragmentController<RingtonePickerDialog> {
// private static final String TAG = "RingtonePickerCtrller";
//
// private final RingtonePickerDialog.OnRingtoneSelectedListener mListener;
//
// public RingtonePickerDialogController(FragmentManager fragmentManager, RingtonePickerDialog.OnRingtoneSelectedListener l) {
// super(fragmentManager);
// mListener = l;
// }
//
// public void show(Uri initialUri, String tag) {
// RingtonePickerDialog dialog = RingtonePickerDialog.newInstance(mListener, initialUri);
// show(dialog, tag);
// }
//
// @Override
// public void tryRestoreCallback(String tag) {
// RingtonePickerDialog dialog = findDialog(tag);
// if (dialog != null) {
// Log.i(TAG, "Restoring on ringtone selected callback");
// dialog.setOnRingtoneSelectedListener(mListener);
// }
// }
// }
// Path: app/src/main/java/com/philliphsu/clock2/settings/ThemedRingtonePreference.java
import com.philliphsu.clock2.dialogs.RingtonePickerDialog;
import com.philliphsu.clock2.dialogs.RingtonePickerDialogController;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.net.Uri;
import android.os.Parcelable;
import android.preference.RingtonePreference;
import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.util.AttributeSet;
/*
* Copyright 2017 Phillip Hsu
*
* This file is part of ClockPlus.
*
* ClockPlus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ClockPlus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ClockPlus. If not, see <http://www.gnu.org/licenses/>.
*/
package com.philliphsu.clock2.settings;
/**
* Created by Phillip Hsu on 9/20/2016.
*
* <p>A modified version of the framework's {@link android.preference.RingtonePreference} that
* uses our {@link RingtonePickerDialog} instead of the system's ringtone picker.</p>
*/
public class ThemedRingtonePreference extends RingtonePreference
implements RingtonePickerDialog.OnRingtoneSelectedListener {
private static final String TAG = "ThemedRingtonePreference";
|
private RingtonePickerDialogController mController;
|
philliphsu/ClockPlus
|
app/src/main/java/com/philliphsu/clock2/list/BaseCursorAdapter.java
|
// Path: app/src/main/java/com/philliphsu/clock2/data/BaseItemCursor.java
// public abstract class BaseItemCursor<T extends ObjectWithId> extends CursorWrapper {
// private static final String TAG = "BaseItemCursor";
//
// public BaseItemCursor(Cursor cursor) {
// super(cursor);
// }
//
// /**
// * @return an item instance configured for the current row,
// * or null if the current row is invalid
// */
// public abstract T getItem();
//
// public long getId() {
// if (isBeforeFirst() || isAfterLast()) {
// Log.e(TAG, "Failed to retrieve id, cursor out of range");
// return -1;
// }
// return getLong(getColumnIndexOrThrow("_id")); // TODO: Refer to a constant instead of a hardcoded value
// }
//
// /**
// * Helper method to determine boolean-valued columns.
// * SQLite does not support a BOOLEAN data type.
// */
// protected boolean isTrue(String columnName) {
// return getInt(getColumnIndexOrThrow(columnName)) == 1;
// }
// }
//
// Path: app/src/main/java/com/philliphsu/clock2/data/ObjectWithId.java
// public abstract class ObjectWithId {
// private long id;
//
// public final long getId() {
// return id;
// }
//
// public final void setId(long id) {
// this.id = id;
// }
//
// public final int getIntId() {
// return (int) id;
// }
// }
|
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.ViewGroup;
import com.philliphsu.clock2.data.BaseItemCursor;
import com.philliphsu.clock2.data.ObjectWithId;
|
/*
* Copyright 2017 Phillip Hsu
*
* This file is part of ClockPlus.
*
* ClockPlus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ClockPlus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ClockPlus. If not, see <http://www.gnu.org/licenses/>.
*/
package com.philliphsu.clock2.list;
/**
* Created by Phillip Hsu on 7/29/2016.
*/
public abstract class BaseCursorAdapter<
T extends ObjectWithId,
VH extends BaseViewHolder<T>,
|
// Path: app/src/main/java/com/philliphsu/clock2/data/BaseItemCursor.java
// public abstract class BaseItemCursor<T extends ObjectWithId> extends CursorWrapper {
// private static final String TAG = "BaseItemCursor";
//
// public BaseItemCursor(Cursor cursor) {
// super(cursor);
// }
//
// /**
// * @return an item instance configured for the current row,
// * or null if the current row is invalid
// */
// public abstract T getItem();
//
// public long getId() {
// if (isBeforeFirst() || isAfterLast()) {
// Log.e(TAG, "Failed to retrieve id, cursor out of range");
// return -1;
// }
// return getLong(getColumnIndexOrThrow("_id")); // TODO: Refer to a constant instead of a hardcoded value
// }
//
// /**
// * Helper method to determine boolean-valued columns.
// * SQLite does not support a BOOLEAN data type.
// */
// protected boolean isTrue(String columnName) {
// return getInt(getColumnIndexOrThrow(columnName)) == 1;
// }
// }
//
// Path: app/src/main/java/com/philliphsu/clock2/data/ObjectWithId.java
// public abstract class ObjectWithId {
// private long id;
//
// public final long getId() {
// return id;
// }
//
// public final void setId(long id) {
// this.id = id;
// }
//
// public final int getIntId() {
// return (int) id;
// }
// }
// Path: app/src/main/java/com/philliphsu/clock2/list/BaseCursorAdapter.java
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.ViewGroup;
import com.philliphsu.clock2.data.BaseItemCursor;
import com.philliphsu.clock2.data.ObjectWithId;
/*
* Copyright 2017 Phillip Hsu
*
* This file is part of ClockPlus.
*
* ClockPlus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ClockPlus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ClockPlus. If not, see <http://www.gnu.org/licenses/>.
*/
package com.philliphsu.clock2.list;
/**
* Created by Phillip Hsu on 7/29/2016.
*/
public abstract class BaseCursorAdapter<
T extends ObjectWithId,
VH extends BaseViewHolder<T>,
|
C extends BaseItemCursor<T>>
|
philliphsu/ClockPlus
|
app/src/main/java/com/philliphsu/clock2/dialogs/AddLabelDialog.java
|
// Path: app/src/main/java/com/philliphsu/clock2/util/KeyboardUtils.java
// public static void showKeyboard(Context c, View v) {
// InputMethodManager imm = (InputMethodManager) c.getSystemService(Context.INPUT_METHOD_SERVICE);
// imm.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT);
// }
|
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.AppCompatEditText;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import com.philliphsu.clock2.R;
import static com.philliphsu.clock2.util.KeyboardUtils.showKeyboard;
|
/*
* Copyright 2017 Phillip Hsu
*
* This file is part of ClockPlus.
*
* ClockPlus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ClockPlus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ClockPlus. If not, see <http://www.gnu.org/licenses/>.
*/
package com.philliphsu.clock2.dialogs;
/**
* Created by Phillip Hsu on 8/30/2016.
*
* TODO: If we have any other needs for a dialog with an EditText, rename this to EditTextDialog,
* and change the callback interface name appropriately.
*/
public class AddLabelDialog extends BaseAlertDialogFragment {
private EditText mEditText;
private OnLabelSetListener mOnLabelSetListener;
private CharSequence mInitialText;
public interface OnLabelSetListener {
void onLabelSet(String label);
}
/**
* @param text the initial text
*/
public static AddLabelDialog newInstance(OnLabelSetListener l, CharSequence text) {
AddLabelDialog dialog = new AddLabelDialog();
dialog.mOnLabelSetListener = l;
dialog.mInitialText = text;
return dialog;
}
@Override
protected AlertDialog createFrom(AlertDialog.Builder builder) {
mEditText = new AppCompatEditText(getActivity());
// Views must have IDs set to automatically save instance state
mEditText.setId(R.id.label);
mEditText.setText(mInitialText);
mEditText.setInputType(
EditorInfo.TYPE_CLASS_TEXT // Needed or else we won't get automatic spacing between words
| EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES);
// TODO: We can use the same value for both directions.
int spacingLeft = getResources().getDimensionPixelSize(R.dimen.item_padding_start);
int spacingRight = getResources().getDimensionPixelSize(R.dimen.item_padding_end);
builder.setTitle(R.string.label)
.setView(mEditText, spacingLeft, 0, spacingRight, 0);
AlertDialog dialog = super.createFrom(builder);
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
|
// Path: app/src/main/java/com/philliphsu/clock2/util/KeyboardUtils.java
// public static void showKeyboard(Context c, View v) {
// InputMethodManager imm = (InputMethodManager) c.getSystemService(Context.INPUT_METHOD_SERVICE);
// imm.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT);
// }
// Path: app/src/main/java/com/philliphsu/clock2/dialogs/AddLabelDialog.java
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.AppCompatEditText;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import com.philliphsu.clock2.R;
import static com.philliphsu.clock2.util.KeyboardUtils.showKeyboard;
/*
* Copyright 2017 Phillip Hsu
*
* This file is part of ClockPlus.
*
* ClockPlus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ClockPlus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ClockPlus. If not, see <http://www.gnu.org/licenses/>.
*/
package com.philliphsu.clock2.dialogs;
/**
* Created by Phillip Hsu on 8/30/2016.
*
* TODO: If we have any other needs for a dialog with an EditText, rename this to EditTextDialog,
* and change the callback interface name appropriately.
*/
public class AddLabelDialog extends BaseAlertDialogFragment {
private EditText mEditText;
private OnLabelSetListener mOnLabelSetListener;
private CharSequence mInitialText;
public interface OnLabelSetListener {
void onLabelSet(String label);
}
/**
* @param text the initial text
*/
public static AddLabelDialog newInstance(OnLabelSetListener l, CharSequence text) {
AddLabelDialog dialog = new AddLabelDialog();
dialog.mOnLabelSetListener = l;
dialog.mInitialText = text;
return dialog;
}
@Override
protected AlertDialog createFrom(AlertDialog.Builder builder) {
mEditText = new AppCompatEditText(getActivity());
// Views must have IDs set to automatically save instance state
mEditText.setId(R.id.label);
mEditText.setText(mInitialText);
mEditText.setInputType(
EditorInfo.TYPE_CLASS_TEXT // Needed or else we won't get automatic spacing between words
| EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES);
// TODO: We can use the same value for both directions.
int spacingLeft = getResources().getDimensionPixelSize(R.dimen.item_padding_start);
int spacingRight = getResources().getDimensionPixelSize(R.dimen.item_padding_end);
builder.setTitle(R.string.label)
.setView(mEditText, spacingLeft, 0, spacingRight, 0);
AlertDialog dialog = super.createFrom(builder);
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
|
showKeyboard(getActivity(), mEditText);
|
philliphsu/ClockPlus
|
app/src/main/java/com/philliphsu/clock2/data/AsyncDatabaseTableUpdateHandler.java
|
// Path: app/src/main/java/com/philliphsu/clock2/list/ScrollHandler.java
// public interface ScrollHandler {
// /**
// * Specifies the stable id of the item we should scroll to in the list.
// * This does not scroll the list. This is useful for preparing to scroll
// * to the item when it does not yet exist in the list.
// */
// void setScrollToStableId(long id);
//
// void scrollToPosition(int position);
// }
|
import com.philliphsu.clock2.list.ScrollHandler;
import android.content.Context;
import android.os.AsyncTask;
|
/*
* Copyright 2017 Phillip Hsu
*
* This file is part of ClockPlus.
*
* ClockPlus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ClockPlus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ClockPlus. If not, see <http://www.gnu.org/licenses/>.
*/
package com.philliphsu.clock2.data;
/**
* Created by Phillip Hsu on 7/1/2016.
*/
public abstract class AsyncDatabaseTableUpdateHandler<
T extends ObjectWithId,
TM extends DatabaseTableManager<T>> {
private static final String TAG = "AsyncDatabaseTableUpdateHandler";
private final Context mAppContext;
|
// Path: app/src/main/java/com/philliphsu/clock2/list/ScrollHandler.java
// public interface ScrollHandler {
// /**
// * Specifies the stable id of the item we should scroll to in the list.
// * This does not scroll the list. This is useful for preparing to scroll
// * to the item when it does not yet exist in the list.
// */
// void setScrollToStableId(long id);
//
// void scrollToPosition(int position);
// }
// Path: app/src/main/java/com/philliphsu/clock2/data/AsyncDatabaseTableUpdateHandler.java
import com.philliphsu.clock2.list.ScrollHandler;
import android.content.Context;
import android.os.AsyncTask;
/*
* Copyright 2017 Phillip Hsu
*
* This file is part of ClockPlus.
*
* ClockPlus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ClockPlus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ClockPlus. If not, see <http://www.gnu.org/licenses/>.
*/
package com.philliphsu.clock2.data;
/**
* Created by Phillip Hsu on 7/1/2016.
*/
public abstract class AsyncDatabaseTableUpdateHandler<
T extends ObjectWithId,
TM extends DatabaseTableManager<T>> {
private static final String TAG = "AsyncDatabaseTableUpdateHandler";
private final Context mAppContext;
|
private final ScrollHandler mScrollHandler;
|
philliphsu/ClockPlus
|
app/src/main/java/com/philliphsu/clock2/alarms/Alarm.java
|
// Path: app/src/main/java/com/philliphsu/clock2/data/ObjectWithId.java
// public abstract class ObjectWithId {
// private long id;
//
// public final long getId() {
// return id;
// }
//
// public final void setId(long id) {
// this.id = id;
// }
//
// public final int getIntId() {
// return (int) id;
// }
// }
//
// Path: app/src/main/java/com/philliphsu/clock2/alarms/misc/DaysOfWeek.java
// public static final int NUM_DAYS = 7;
//
// Path: app/src/main/java/com/philliphsu/clock2/alarms/misc/DaysOfWeek.java
// public static final int SATURDAY = 6;
//
// Path: app/src/main/java/com/philliphsu/clock2/alarms/misc/DaysOfWeek.java
// public static final int SUNDAY = 0;
|
import static com.philliphsu.clock2.alarms.misc.DaysOfWeek.NUM_DAYS;
import static com.philliphsu.clock2.alarms.misc.DaysOfWeek.SATURDAY;
import static com.philliphsu.clock2.alarms.misc.DaysOfWeek.SUNDAY;
import android.os.Parcel;
import android.os.Parcelable;
import com.google.auto.value.AutoValue;
import com.philliphsu.clock2.data.ObjectWithId;
import org.json.JSONObject;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.concurrent.TimeUnit;
|
/*
* Copyright 2017 Phillip Hsu
*
* This file is part of ClockPlus.
*
* ClockPlus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ClockPlus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ClockPlus. If not, see <http://www.gnu.org/licenses/>.
*/
package com.philliphsu.clock2.alarms;
/**
* Created by Phillip Hsu on 5/26/2016.
*/
@AutoValue
public abstract class Alarm extends ObjectWithId implements Parcelable {
private static final int MAX_MINUTES_CAN_SNOOZE = 30;
// =================== MUTABLE =======================
private long snoozingUntilMillis;
private boolean enabled;
|
// Path: app/src/main/java/com/philliphsu/clock2/data/ObjectWithId.java
// public abstract class ObjectWithId {
// private long id;
//
// public final long getId() {
// return id;
// }
//
// public final void setId(long id) {
// this.id = id;
// }
//
// public final int getIntId() {
// return (int) id;
// }
// }
//
// Path: app/src/main/java/com/philliphsu/clock2/alarms/misc/DaysOfWeek.java
// public static final int NUM_DAYS = 7;
//
// Path: app/src/main/java/com/philliphsu/clock2/alarms/misc/DaysOfWeek.java
// public static final int SATURDAY = 6;
//
// Path: app/src/main/java/com/philliphsu/clock2/alarms/misc/DaysOfWeek.java
// public static final int SUNDAY = 0;
// Path: app/src/main/java/com/philliphsu/clock2/alarms/Alarm.java
import static com.philliphsu.clock2.alarms.misc.DaysOfWeek.NUM_DAYS;
import static com.philliphsu.clock2.alarms.misc.DaysOfWeek.SATURDAY;
import static com.philliphsu.clock2.alarms.misc.DaysOfWeek.SUNDAY;
import android.os.Parcel;
import android.os.Parcelable;
import com.google.auto.value.AutoValue;
import com.philliphsu.clock2.data.ObjectWithId;
import org.json.JSONObject;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.concurrent.TimeUnit;
/*
* Copyright 2017 Phillip Hsu
*
* This file is part of ClockPlus.
*
* ClockPlus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ClockPlus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ClockPlus. If not, see <http://www.gnu.org/licenses/>.
*/
package com.philliphsu.clock2.alarms;
/**
* Created by Phillip Hsu on 5/26/2016.
*/
@AutoValue
public abstract class Alarm extends ObjectWithId implements Parcelable {
private static final int MAX_MINUTES_CAN_SNOOZE = 30;
// =================== MUTABLE =======================
private long snoozingUntilMillis;
private boolean enabled;
|
private final boolean[] recurringDays = new boolean[NUM_DAYS];
|
philliphsu/ClockPlus
|
app/src/main/java/com/philliphsu/clock2/alarms/Alarm.java
|
// Path: app/src/main/java/com/philliphsu/clock2/data/ObjectWithId.java
// public abstract class ObjectWithId {
// private long id;
//
// public final long getId() {
// return id;
// }
//
// public final void setId(long id) {
// this.id = id;
// }
//
// public final int getIntId() {
// return (int) id;
// }
// }
//
// Path: app/src/main/java/com/philliphsu/clock2/alarms/misc/DaysOfWeek.java
// public static final int NUM_DAYS = 7;
//
// Path: app/src/main/java/com/philliphsu/clock2/alarms/misc/DaysOfWeek.java
// public static final int SATURDAY = 6;
//
// Path: app/src/main/java/com/philliphsu/clock2/alarms/misc/DaysOfWeek.java
// public static final int SUNDAY = 0;
|
import static com.philliphsu.clock2.alarms.misc.DaysOfWeek.NUM_DAYS;
import static com.philliphsu.clock2.alarms.misc.DaysOfWeek.SATURDAY;
import static com.philliphsu.clock2.alarms.misc.DaysOfWeek.SUNDAY;
import android.os.Parcel;
import android.os.Parcelable;
import com.google.auto.value.AutoValue;
import com.philliphsu.clock2.data.ObjectWithId;
import org.json.JSONObject;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.concurrent.TimeUnit;
|
/*
* Copyright 2017 Phillip Hsu
*
* This file is part of ClockPlus.
*
* ClockPlus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ClockPlus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ClockPlus. If not, see <http://www.gnu.org/licenses/>.
*/
package com.philliphsu.clock2.alarms;
/**
* Created by Phillip Hsu on 5/26/2016.
*/
@AutoValue
public abstract class Alarm extends ObjectWithId implements Parcelable {
private static final int MAX_MINUTES_CAN_SNOOZE = 30;
// =================== MUTABLE =======================
private long snoozingUntilMillis;
private boolean enabled;
private final boolean[] recurringDays = new boolean[NUM_DAYS];
private boolean ignoreUpcomingRingTime;
// ====================================================
public abstract int hour();
public abstract int minutes();
public abstract String label();
public abstract String ringtone();
public abstract boolean vibrates();
/** Initializes a Builder to the same property values as this instance */
public abstract Builder toBuilder();
@Deprecated
public static Alarm create(JSONObject jsonObject) {
throw new UnsupportedOperationException();
}
public void copyMutableFieldsTo(Alarm target) {
target.setId(this.getId());
target.snoozingUntilMillis = this.snoozingUntilMillis;
target.enabled = this.enabled;
System.arraycopy(this.recurringDays, 0, target.recurringDays, 0, NUM_DAYS);
target.ignoreUpcomingRingTime = this.ignoreUpcomingRingTime;
}
public static Builder builder() {
// Unfortunately, default values must be provided for generated Builders.
// Fields that were not set when build() is called will throw an exception.
return new AutoValue_Alarm.Builder()
.hour(0)
.minutes(0)
.label("")
.ringtone("")
.vibrates(false);
}
public void snooze(int minutes) {
if (minutes <= 0 || minutes > MAX_MINUTES_CAN_SNOOZE)
throw new IllegalArgumentException("Cannot snooze for "+minutes+" minutes");
snoozingUntilMillis = System.currentTimeMillis() + minutes * 60000;
}
public long snoozingUntil() {
return isSnoozed() ? snoozingUntilMillis : 0;
}
public boolean isSnoozed() {
if (snoozingUntilMillis <= System.currentTimeMillis()) {
snoozingUntilMillis = 0;
return false;
}
return true;
}
/** <b>ONLY CALL THIS WHEN CREATING AN ALARM INSTANCE FROM A CURSOR</b> */
// TODO: To be even more safe, create a ctor that takes a Cursor and
// initialize the instance here instead of in AlarmDatabaseHelper.
public void setSnoozing(long snoozingUntilMillis) {
this.snoozingUntilMillis = snoozingUntilMillis;
}
public void stopSnoozing() {
snoozingUntilMillis = 0;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public boolean isEnabled() {
return enabled;
}
public boolean[] recurringDays() {
return recurringDays;
}
public void setRecurring(int day, boolean recurring) {
checkDay(day);
recurringDays[day] = recurring;
}
public boolean isRecurring(int day) {
checkDay(day);
return recurringDays[day];
}
public boolean hasRecurrence() {
return numRecurringDays() > 0;
}
public int numRecurringDays() {
int count = 0;
for (boolean b : recurringDays)
if (b) count++;
return count;
}
public void ignoreUpcomingRingTime(boolean ignore) {
ignoreUpcomingRingTime = ignore;
}
public boolean isIgnoringUpcomingRingTime() {
return ignoreUpcomingRingTime;
}
public long ringsAt() {
// Always with respect to the current date and time
Calendar calendar = new GregorianCalendar();
calendar.set(Calendar.HOUR_OF_DAY, hour());
calendar.set(Calendar.MINUTE, minutes());
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
long baseRingTime = calendar.getTimeInMillis();
if (!hasRecurrence()) {
if (baseRingTime <= System.currentTimeMillis()) {
// The specified time has passed for today
baseRingTime += TimeUnit.DAYS.toMillis(1);
}
return baseRingTime;
} else {
// Compute the ring time just for the next closest recurring day.
// Remember that day constants defined in the Calendar class are
// not zero-based like ours, so we have to compensate with an offset
// of magnitude one, with the appropriate sign based on the situation.
int weekdayToday = calendar.get(Calendar.DAY_OF_WEEK);
int numDaysFromToday = -1;
|
// Path: app/src/main/java/com/philliphsu/clock2/data/ObjectWithId.java
// public abstract class ObjectWithId {
// private long id;
//
// public final long getId() {
// return id;
// }
//
// public final void setId(long id) {
// this.id = id;
// }
//
// public final int getIntId() {
// return (int) id;
// }
// }
//
// Path: app/src/main/java/com/philliphsu/clock2/alarms/misc/DaysOfWeek.java
// public static final int NUM_DAYS = 7;
//
// Path: app/src/main/java/com/philliphsu/clock2/alarms/misc/DaysOfWeek.java
// public static final int SATURDAY = 6;
//
// Path: app/src/main/java/com/philliphsu/clock2/alarms/misc/DaysOfWeek.java
// public static final int SUNDAY = 0;
// Path: app/src/main/java/com/philliphsu/clock2/alarms/Alarm.java
import static com.philliphsu.clock2.alarms.misc.DaysOfWeek.NUM_DAYS;
import static com.philliphsu.clock2.alarms.misc.DaysOfWeek.SATURDAY;
import static com.philliphsu.clock2.alarms.misc.DaysOfWeek.SUNDAY;
import android.os.Parcel;
import android.os.Parcelable;
import com.google.auto.value.AutoValue;
import com.philliphsu.clock2.data.ObjectWithId;
import org.json.JSONObject;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.concurrent.TimeUnit;
/*
* Copyright 2017 Phillip Hsu
*
* This file is part of ClockPlus.
*
* ClockPlus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ClockPlus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ClockPlus. If not, see <http://www.gnu.org/licenses/>.
*/
package com.philliphsu.clock2.alarms;
/**
* Created by Phillip Hsu on 5/26/2016.
*/
@AutoValue
public abstract class Alarm extends ObjectWithId implements Parcelable {
private static final int MAX_MINUTES_CAN_SNOOZE = 30;
// =================== MUTABLE =======================
private long snoozingUntilMillis;
private boolean enabled;
private final boolean[] recurringDays = new boolean[NUM_DAYS];
private boolean ignoreUpcomingRingTime;
// ====================================================
public abstract int hour();
public abstract int minutes();
public abstract String label();
public abstract String ringtone();
public abstract boolean vibrates();
/** Initializes a Builder to the same property values as this instance */
public abstract Builder toBuilder();
@Deprecated
public static Alarm create(JSONObject jsonObject) {
throw new UnsupportedOperationException();
}
public void copyMutableFieldsTo(Alarm target) {
target.setId(this.getId());
target.snoozingUntilMillis = this.snoozingUntilMillis;
target.enabled = this.enabled;
System.arraycopy(this.recurringDays, 0, target.recurringDays, 0, NUM_DAYS);
target.ignoreUpcomingRingTime = this.ignoreUpcomingRingTime;
}
public static Builder builder() {
// Unfortunately, default values must be provided for generated Builders.
// Fields that were not set when build() is called will throw an exception.
return new AutoValue_Alarm.Builder()
.hour(0)
.minutes(0)
.label("")
.ringtone("")
.vibrates(false);
}
public void snooze(int minutes) {
if (minutes <= 0 || minutes > MAX_MINUTES_CAN_SNOOZE)
throw new IllegalArgumentException("Cannot snooze for "+minutes+" minutes");
snoozingUntilMillis = System.currentTimeMillis() + minutes * 60000;
}
public long snoozingUntil() {
return isSnoozed() ? snoozingUntilMillis : 0;
}
public boolean isSnoozed() {
if (snoozingUntilMillis <= System.currentTimeMillis()) {
snoozingUntilMillis = 0;
return false;
}
return true;
}
/** <b>ONLY CALL THIS WHEN CREATING AN ALARM INSTANCE FROM A CURSOR</b> */
// TODO: To be even more safe, create a ctor that takes a Cursor and
// initialize the instance here instead of in AlarmDatabaseHelper.
public void setSnoozing(long snoozingUntilMillis) {
this.snoozingUntilMillis = snoozingUntilMillis;
}
public void stopSnoozing() {
snoozingUntilMillis = 0;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public boolean isEnabled() {
return enabled;
}
public boolean[] recurringDays() {
return recurringDays;
}
public void setRecurring(int day, boolean recurring) {
checkDay(day);
recurringDays[day] = recurring;
}
public boolean isRecurring(int day) {
checkDay(day);
return recurringDays[day];
}
public boolean hasRecurrence() {
return numRecurringDays() > 0;
}
public int numRecurringDays() {
int count = 0;
for (boolean b : recurringDays)
if (b) count++;
return count;
}
public void ignoreUpcomingRingTime(boolean ignore) {
ignoreUpcomingRingTime = ignore;
}
public boolean isIgnoringUpcomingRingTime() {
return ignoreUpcomingRingTime;
}
public long ringsAt() {
// Always with respect to the current date and time
Calendar calendar = new GregorianCalendar();
calendar.set(Calendar.HOUR_OF_DAY, hour());
calendar.set(Calendar.MINUTE, minutes());
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
long baseRingTime = calendar.getTimeInMillis();
if (!hasRecurrence()) {
if (baseRingTime <= System.currentTimeMillis()) {
// The specified time has passed for today
baseRingTime += TimeUnit.DAYS.toMillis(1);
}
return baseRingTime;
} else {
// Compute the ring time just for the next closest recurring day.
// Remember that day constants defined in the Calendar class are
// not zero-based like ours, so we have to compensate with an offset
// of magnitude one, with the appropriate sign based on the situation.
int weekdayToday = calendar.get(Calendar.DAY_OF_WEEK);
int numDaysFromToday = -1;
|
for (int i = weekdayToday; i <= Calendar.SATURDAY; i++) {
|
philliphsu/ClockPlus
|
app/src/main/java/com/philliphsu/clock2/data/SQLiteCursorLoader.java
|
// Path: app/src/main/java/com/philliphsu/clock2/util/LocalBroadcastHelper.java
// public final class LocalBroadcastHelper {
//
// /** Sends a local broadcast using an intent with the action specified */
// public static void sendBroadcast(Context context, String action) {
// sendBroadcast(context, action, null);
// }
//
// /** Sends a local broadcast using an intent with the action and the extras specified */
// public static void sendBroadcast(Context context, String action, Bundle extras) {
// Intent intent = new Intent(action);
// if (extras != null) {
// intent.putExtras(extras);
// }
// LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
// }
//
// /** Registers a BroadcastReceiver that filters intents by the actions specified */
// public static void registerReceiver(Context context, BroadcastReceiver receiver, String... actions) {
// IntentFilter filter = new IntentFilter();
// for (String action : actions)
// filter.addAction(action);
// LocalBroadcastManager.getInstance(context).registerReceiver(receiver, filter);
// }
//
// public static void unregisterReceiver(Context context, BroadcastReceiver receiver) {
// LocalBroadcastManager.getInstance(context).unregisterReceiver(receiver);
// }
//
// private LocalBroadcastHelper() {}
// }
|
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.support.v4.content.AsyncTaskLoader;
import android.util.Log;
import com.philliphsu.clock2.util.LocalBroadcastHelper;
|
/*
* Copyright 2017 Phillip Hsu
*
* This file is part of ClockPlus.
*
* ClockPlus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ClockPlus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ClockPlus. If not, see <http://www.gnu.org/licenses/>.
*/
package com.philliphsu.clock2.data;
/**
* Created by Phillip Hsu on 6/28/2016.
*
* Efficiently loads and holds a Cursor.
*/
public abstract class SQLiteCursorLoader<
T extends ObjectWithId,
C extends BaseItemCursor<T>>
extends AsyncTaskLoader<C> {
private static final String TAG = "SQLiteCursorLoader";
private C mCursor;
private OnContentChangeReceiver mOnContentChangeReceiver;
public SQLiteCursorLoader(Context context) {
super(context);
}
protected abstract C loadCursor();
/**
* @return the Intent action that will be registered to this Loader
* for receiving broadcasts about underlying data changes to our
* designated database table
*/
protected abstract String getOnContentChangeAction();
/* Runs on a worker thread */
@Override
public C loadInBackground() {
C cursor = loadCursor();
if (cursor != null) {
// Ensure that the content window is filled
// Ensure that the data is available in memory once it is
// passed to the main thread
cursor.getCount();
}
return cursor;
}
/* Runs on the UI thread */
@Override
public void deliverResult(C cursor) {
if (isReset()) {
// An async query came in while the loader is stopped
if (cursor != null) {
cursor.close();
}
return;
}
Cursor oldCursor = mCursor;
mCursor = cursor;
if (isStarted()) {
super.deliverResult(cursor);
}
// Close the old cursor because it is no longer needed.
// Because an existing cursor may be cached and redelivered, it is important
// to make sure that the old cursor and the new cursor are not the
// same before the old cursor is closed.
if (oldCursor != null && oldCursor != cursor && !oldCursor.isClosed()) {
oldCursor.close();
}
}
// Refer to the docs if you wish to understand the rest of the API as used below.
@Override
protected void onStartLoading() {
if (mCursor != null) {
deliverResult(mCursor);
}
if (mOnContentChangeReceiver == null) {
mOnContentChangeReceiver = new OnContentChangeReceiver();
|
// Path: app/src/main/java/com/philliphsu/clock2/util/LocalBroadcastHelper.java
// public final class LocalBroadcastHelper {
//
// /** Sends a local broadcast using an intent with the action specified */
// public static void sendBroadcast(Context context, String action) {
// sendBroadcast(context, action, null);
// }
//
// /** Sends a local broadcast using an intent with the action and the extras specified */
// public static void sendBroadcast(Context context, String action, Bundle extras) {
// Intent intent = new Intent(action);
// if (extras != null) {
// intent.putExtras(extras);
// }
// LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
// }
//
// /** Registers a BroadcastReceiver that filters intents by the actions specified */
// public static void registerReceiver(Context context, BroadcastReceiver receiver, String... actions) {
// IntentFilter filter = new IntentFilter();
// for (String action : actions)
// filter.addAction(action);
// LocalBroadcastManager.getInstance(context).registerReceiver(receiver, filter);
// }
//
// public static void unregisterReceiver(Context context, BroadcastReceiver receiver) {
// LocalBroadcastManager.getInstance(context).unregisterReceiver(receiver);
// }
//
// private LocalBroadcastHelper() {}
// }
// Path: app/src/main/java/com/philliphsu/clock2/data/SQLiteCursorLoader.java
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.support.v4.content.AsyncTaskLoader;
import android.util.Log;
import com.philliphsu.clock2.util.LocalBroadcastHelper;
/*
* Copyright 2017 Phillip Hsu
*
* This file is part of ClockPlus.
*
* ClockPlus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ClockPlus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ClockPlus. If not, see <http://www.gnu.org/licenses/>.
*/
package com.philliphsu.clock2.data;
/**
* Created by Phillip Hsu on 6/28/2016.
*
* Efficiently loads and holds a Cursor.
*/
public abstract class SQLiteCursorLoader<
T extends ObjectWithId,
C extends BaseItemCursor<T>>
extends AsyncTaskLoader<C> {
private static final String TAG = "SQLiteCursorLoader";
private C mCursor;
private OnContentChangeReceiver mOnContentChangeReceiver;
public SQLiteCursorLoader(Context context) {
super(context);
}
protected abstract C loadCursor();
/**
* @return the Intent action that will be registered to this Loader
* for receiving broadcasts about underlying data changes to our
* designated database table
*/
protected abstract String getOnContentChangeAction();
/* Runs on a worker thread */
@Override
public C loadInBackground() {
C cursor = loadCursor();
if (cursor != null) {
// Ensure that the content window is filled
// Ensure that the data is available in memory once it is
// passed to the main thread
cursor.getCount();
}
return cursor;
}
/* Runs on the UI thread */
@Override
public void deliverResult(C cursor) {
if (isReset()) {
// An async query came in while the loader is stopped
if (cursor != null) {
cursor.close();
}
return;
}
Cursor oldCursor = mCursor;
mCursor = cursor;
if (isStarted()) {
super.deliverResult(cursor);
}
// Close the old cursor because it is no longer needed.
// Because an existing cursor may be cached and redelivered, it is important
// to make sure that the old cursor and the new cursor are not the
// same before the old cursor is closed.
if (oldCursor != null && oldCursor != cursor && !oldCursor.isClosed()) {
oldCursor.close();
}
}
// Refer to the docs if you wish to understand the rest of the API as used below.
@Override
protected void onStartLoading() {
if (mCursor != null) {
deliverResult(mCursor);
}
if (mOnContentChangeReceiver == null) {
mOnContentChangeReceiver = new OnContentChangeReceiver();
|
LocalBroadcastHelper.registerReceiver(getContext(),
|
philliphsu/ClockPlus
|
app/src/main/java/com/philliphsu/clock2/data/DatabaseTableManager.java
|
// Path: app/src/main/java/com/philliphsu/clock2/util/LocalBroadcastHelper.java
// public final class LocalBroadcastHelper {
//
// /** Sends a local broadcast using an intent with the action specified */
// public static void sendBroadcast(Context context, String action) {
// sendBroadcast(context, action, null);
// }
//
// /** Sends a local broadcast using an intent with the action and the extras specified */
// public static void sendBroadcast(Context context, String action, Bundle extras) {
// Intent intent = new Intent(action);
// if (extras != null) {
// intent.putExtras(extras);
// }
// LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
// }
//
// /** Registers a BroadcastReceiver that filters intents by the actions specified */
// public static void registerReceiver(Context context, BroadcastReceiver receiver, String... actions) {
// IntentFilter filter = new IntentFilter();
// for (String action : actions)
// filter.addAction(action);
// LocalBroadcastManager.getInstance(context).registerReceiver(receiver, filter);
// }
//
// public static void unregisterReceiver(Context context, BroadcastReceiver receiver) {
// LocalBroadcastManager.getInstance(context).unregisterReceiver(receiver);
// }
//
// private LocalBroadcastHelper() {}
// }
|
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import com.philliphsu.clock2.util.LocalBroadcastHelper;
|
// positions as it binds VHs.
c.moveToFirst();
return c;
}
public Cursor queryItems() {
// Select all rows and columns
return queryItems(null, null);
}
protected Cursor queryItems(String where, String limit) {
return mDbHelper.getReadableDatabase().query(getTableName(),
null, // All columns
where, // Selection, i.e. where COLUMN_* = [value we're looking for]
null, // selection args, none b/c id already specified in selection
null, // group by
null, // having
getQuerySortOrder(), // order/sort by
limit); // limit
}
/**
* Deletes all rows in this table.
*/
public final void clear() {
mDbHelper.getWritableDatabase().delete(getTableName(), null/*all rows*/, null);
notifyContentChanged();
}
private void notifyContentChanged() {
|
// Path: app/src/main/java/com/philliphsu/clock2/util/LocalBroadcastHelper.java
// public final class LocalBroadcastHelper {
//
// /** Sends a local broadcast using an intent with the action specified */
// public static void sendBroadcast(Context context, String action) {
// sendBroadcast(context, action, null);
// }
//
// /** Sends a local broadcast using an intent with the action and the extras specified */
// public static void sendBroadcast(Context context, String action, Bundle extras) {
// Intent intent = new Intent(action);
// if (extras != null) {
// intent.putExtras(extras);
// }
// LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
// }
//
// /** Registers a BroadcastReceiver that filters intents by the actions specified */
// public static void registerReceiver(Context context, BroadcastReceiver receiver, String... actions) {
// IntentFilter filter = new IntentFilter();
// for (String action : actions)
// filter.addAction(action);
// LocalBroadcastManager.getInstance(context).registerReceiver(receiver, filter);
// }
//
// public static void unregisterReceiver(Context context, BroadcastReceiver receiver) {
// LocalBroadcastManager.getInstance(context).unregisterReceiver(receiver);
// }
//
// private LocalBroadcastHelper() {}
// }
// Path: app/src/main/java/com/philliphsu/clock2/data/DatabaseTableManager.java
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import com.philliphsu.clock2.util.LocalBroadcastHelper;
// positions as it binds VHs.
c.moveToFirst();
return c;
}
public Cursor queryItems() {
// Select all rows and columns
return queryItems(null, null);
}
protected Cursor queryItems(String where, String limit) {
return mDbHelper.getReadableDatabase().query(getTableName(),
null, // All columns
where, // Selection, i.e. where COLUMN_* = [value we're looking for]
null, // selection args, none b/c id already specified in selection
null, // group by
null, // having
getQuerySortOrder(), // order/sort by
limit); // limit
}
/**
* Deletes all rows in this table.
*/
public final void clear() {
mDbHelper.getWritableDatabase().delete(getTableName(), null/*all rows*/, null);
notifyContentChanged();
}
private void notifyContentChanged() {
|
LocalBroadcastHelper.sendBroadcast(mAppContext, getOnContentChangeAction());
|
philliphsu/ClockPlus
|
app/src/main/java/com/philliphsu/clock2/list/RecyclerViewFragment.java
|
// Path: app/src/main/java/com/philliphsu/clock2/BaseFragment.java
// public abstract class BaseFragment extends Fragment {
// /**
// * Required empty public constructor. Subclasses do not
// * need to implement their own.
// */
// public BaseFragment() {}
//
// /**
// * @return the layout resource for this Fragment
// */
// @LayoutRes
// protected abstract int contentLayout();
//
// @Nullable
// @Override
// public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
// View view = inflater.inflate(contentLayout(), container, false);
// ButterKnife.bind(this, view);
// return view;
// }
//
// @Override
// public void onDestroyView() {
// super.onDestroyView();
// ButterKnife.unbind(this); // Only for fragments!
// }
//
// /**
// * Callback invoked when this Fragment is part of a ViewPager and it has been
// * selected, as indicated by {@link android.support.v4.view.ViewPager.OnPageChangeListener#onPageSelected(int)
// * onPageSelected(int)}.
// */
// public void onPageSelected() {
// // TODO: Consider making this abstract. The reason it wasn't abstract in the first place
// // is not all Fragments in our ViewPager need to do things upon being selected. As such,
// // those Fragments' classes would just end up stubbing this implementation.
// }
// }
//
// Path: app/src/main/java/com/philliphsu/clock2/data/BaseItemCursor.java
// public abstract class BaseItemCursor<T extends ObjectWithId> extends CursorWrapper {
// private static final String TAG = "BaseItemCursor";
//
// public BaseItemCursor(Cursor cursor) {
// super(cursor);
// }
//
// /**
// * @return an item instance configured for the current row,
// * or null if the current row is invalid
// */
// public abstract T getItem();
//
// public long getId() {
// if (isBeforeFirst() || isAfterLast()) {
// Log.e(TAG, "Failed to retrieve id, cursor out of range");
// return -1;
// }
// return getLong(getColumnIndexOrThrow("_id")); // TODO: Refer to a constant instead of a hardcoded value
// }
//
// /**
// * Helper method to determine boolean-valued columns.
// * SQLite does not support a BOOLEAN data type.
// */
// protected boolean isTrue(String columnName) {
// return getInt(getColumnIndexOrThrow(columnName)) == 1;
// }
// }
//
// Path: app/src/main/java/com/philliphsu/clock2/data/ObjectWithId.java
// public abstract class ObjectWithId {
// private long id;
//
// public final long getId() {
// return id;
// }
//
// public final void setId(long id) {
// this.id = id;
// }
//
// public final int getIntId() {
// return (int) id;
// }
// }
|
import android.widget.TextView;
import com.philliphsu.clock2.BaseFragment;
import com.philliphsu.clock2.R;
import com.philliphsu.clock2.data.BaseItemCursor;
import com.philliphsu.clock2.data.ObjectWithId;
import butterknife.Bind;
import android.os.Bundle;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
|
/*
* Copyright 2017 Phillip Hsu
*
* This file is part of ClockPlus.
*
* ClockPlus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ClockPlus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ClockPlus. If not, see <http://www.gnu.org/licenses/>.
*/
package com.philliphsu.clock2.list;
/**
* Created by Phillip Hsu on 7/26/2016.
*/
public abstract class RecyclerViewFragment<
T extends ObjectWithId,
VH extends BaseViewHolder<T>,
|
// Path: app/src/main/java/com/philliphsu/clock2/BaseFragment.java
// public abstract class BaseFragment extends Fragment {
// /**
// * Required empty public constructor. Subclasses do not
// * need to implement their own.
// */
// public BaseFragment() {}
//
// /**
// * @return the layout resource for this Fragment
// */
// @LayoutRes
// protected abstract int contentLayout();
//
// @Nullable
// @Override
// public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
// View view = inflater.inflate(contentLayout(), container, false);
// ButterKnife.bind(this, view);
// return view;
// }
//
// @Override
// public void onDestroyView() {
// super.onDestroyView();
// ButterKnife.unbind(this); // Only for fragments!
// }
//
// /**
// * Callback invoked when this Fragment is part of a ViewPager and it has been
// * selected, as indicated by {@link android.support.v4.view.ViewPager.OnPageChangeListener#onPageSelected(int)
// * onPageSelected(int)}.
// */
// public void onPageSelected() {
// // TODO: Consider making this abstract. The reason it wasn't abstract in the first place
// // is not all Fragments in our ViewPager need to do things upon being selected. As such,
// // those Fragments' classes would just end up stubbing this implementation.
// }
// }
//
// Path: app/src/main/java/com/philliphsu/clock2/data/BaseItemCursor.java
// public abstract class BaseItemCursor<T extends ObjectWithId> extends CursorWrapper {
// private static final String TAG = "BaseItemCursor";
//
// public BaseItemCursor(Cursor cursor) {
// super(cursor);
// }
//
// /**
// * @return an item instance configured for the current row,
// * or null if the current row is invalid
// */
// public abstract T getItem();
//
// public long getId() {
// if (isBeforeFirst() || isAfterLast()) {
// Log.e(TAG, "Failed to retrieve id, cursor out of range");
// return -1;
// }
// return getLong(getColumnIndexOrThrow("_id")); // TODO: Refer to a constant instead of a hardcoded value
// }
//
// /**
// * Helper method to determine boolean-valued columns.
// * SQLite does not support a BOOLEAN data type.
// */
// protected boolean isTrue(String columnName) {
// return getInt(getColumnIndexOrThrow(columnName)) == 1;
// }
// }
//
// Path: app/src/main/java/com/philliphsu/clock2/data/ObjectWithId.java
// public abstract class ObjectWithId {
// private long id;
//
// public final long getId() {
// return id;
// }
//
// public final void setId(long id) {
// this.id = id;
// }
//
// public final int getIntId() {
// return (int) id;
// }
// }
// Path: app/src/main/java/com/philliphsu/clock2/list/RecyclerViewFragment.java
import android.widget.TextView;
import com.philliphsu.clock2.BaseFragment;
import com.philliphsu.clock2.R;
import com.philliphsu.clock2.data.BaseItemCursor;
import com.philliphsu.clock2.data.ObjectWithId;
import butterknife.Bind;
import android.os.Bundle;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/*
* Copyright 2017 Phillip Hsu
*
* This file is part of ClockPlus.
*
* ClockPlus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ClockPlus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ClockPlus. If not, see <http://www.gnu.org/licenses/>.
*/
package com.philliphsu.clock2.list;
/**
* Created by Phillip Hsu on 7/26/2016.
*/
public abstract class RecyclerViewFragment<
T extends ObjectWithId,
VH extends BaseViewHolder<T>,
|
C extends BaseItemCursor<T>,
|
philliphsu/ClockPlus
|
app/src/main/java/com/philliphsu/clock2/list/RecyclerViewFragment.java
|
// Path: app/src/main/java/com/philliphsu/clock2/BaseFragment.java
// public abstract class BaseFragment extends Fragment {
// /**
// * Required empty public constructor. Subclasses do not
// * need to implement their own.
// */
// public BaseFragment() {}
//
// /**
// * @return the layout resource for this Fragment
// */
// @LayoutRes
// protected abstract int contentLayout();
//
// @Nullable
// @Override
// public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
// View view = inflater.inflate(contentLayout(), container, false);
// ButterKnife.bind(this, view);
// return view;
// }
//
// @Override
// public void onDestroyView() {
// super.onDestroyView();
// ButterKnife.unbind(this); // Only for fragments!
// }
//
// /**
// * Callback invoked when this Fragment is part of a ViewPager and it has been
// * selected, as indicated by {@link android.support.v4.view.ViewPager.OnPageChangeListener#onPageSelected(int)
// * onPageSelected(int)}.
// */
// public void onPageSelected() {
// // TODO: Consider making this abstract. The reason it wasn't abstract in the first place
// // is not all Fragments in our ViewPager need to do things upon being selected. As such,
// // those Fragments' classes would just end up stubbing this implementation.
// }
// }
//
// Path: app/src/main/java/com/philliphsu/clock2/data/BaseItemCursor.java
// public abstract class BaseItemCursor<T extends ObjectWithId> extends CursorWrapper {
// private static final String TAG = "BaseItemCursor";
//
// public BaseItemCursor(Cursor cursor) {
// super(cursor);
// }
//
// /**
// * @return an item instance configured for the current row,
// * or null if the current row is invalid
// */
// public abstract T getItem();
//
// public long getId() {
// if (isBeforeFirst() || isAfterLast()) {
// Log.e(TAG, "Failed to retrieve id, cursor out of range");
// return -1;
// }
// return getLong(getColumnIndexOrThrow("_id")); // TODO: Refer to a constant instead of a hardcoded value
// }
//
// /**
// * Helper method to determine boolean-valued columns.
// * SQLite does not support a BOOLEAN data type.
// */
// protected boolean isTrue(String columnName) {
// return getInt(getColumnIndexOrThrow(columnName)) == 1;
// }
// }
//
// Path: app/src/main/java/com/philliphsu/clock2/data/ObjectWithId.java
// public abstract class ObjectWithId {
// private long id;
//
// public final long getId() {
// return id;
// }
//
// public final void setId(long id) {
// this.id = id;
// }
//
// public final int getIntId() {
// return (int) id;
// }
// }
|
import android.widget.TextView;
import com.philliphsu.clock2.BaseFragment;
import com.philliphsu.clock2.R;
import com.philliphsu.clock2.data.BaseItemCursor;
import com.philliphsu.clock2.data.ObjectWithId;
import butterknife.Bind;
import android.os.Bundle;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
|
/*
* Copyright 2017 Phillip Hsu
*
* This file is part of ClockPlus.
*
* ClockPlus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ClockPlus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ClockPlus. If not, see <http://www.gnu.org/licenses/>.
*/
package com.philliphsu.clock2.list;
/**
* Created by Phillip Hsu on 7/26/2016.
*/
public abstract class RecyclerViewFragment<
T extends ObjectWithId,
VH extends BaseViewHolder<T>,
C extends BaseItemCursor<T>,
A extends BaseCursorAdapter<T, VH, C>>
|
// Path: app/src/main/java/com/philliphsu/clock2/BaseFragment.java
// public abstract class BaseFragment extends Fragment {
// /**
// * Required empty public constructor. Subclasses do not
// * need to implement their own.
// */
// public BaseFragment() {}
//
// /**
// * @return the layout resource for this Fragment
// */
// @LayoutRes
// protected abstract int contentLayout();
//
// @Nullable
// @Override
// public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
// View view = inflater.inflate(contentLayout(), container, false);
// ButterKnife.bind(this, view);
// return view;
// }
//
// @Override
// public void onDestroyView() {
// super.onDestroyView();
// ButterKnife.unbind(this); // Only for fragments!
// }
//
// /**
// * Callback invoked when this Fragment is part of a ViewPager and it has been
// * selected, as indicated by {@link android.support.v4.view.ViewPager.OnPageChangeListener#onPageSelected(int)
// * onPageSelected(int)}.
// */
// public void onPageSelected() {
// // TODO: Consider making this abstract. The reason it wasn't abstract in the first place
// // is not all Fragments in our ViewPager need to do things upon being selected. As such,
// // those Fragments' classes would just end up stubbing this implementation.
// }
// }
//
// Path: app/src/main/java/com/philliphsu/clock2/data/BaseItemCursor.java
// public abstract class BaseItemCursor<T extends ObjectWithId> extends CursorWrapper {
// private static final String TAG = "BaseItemCursor";
//
// public BaseItemCursor(Cursor cursor) {
// super(cursor);
// }
//
// /**
// * @return an item instance configured for the current row,
// * or null if the current row is invalid
// */
// public abstract T getItem();
//
// public long getId() {
// if (isBeforeFirst() || isAfterLast()) {
// Log.e(TAG, "Failed to retrieve id, cursor out of range");
// return -1;
// }
// return getLong(getColumnIndexOrThrow("_id")); // TODO: Refer to a constant instead of a hardcoded value
// }
//
// /**
// * Helper method to determine boolean-valued columns.
// * SQLite does not support a BOOLEAN data type.
// */
// protected boolean isTrue(String columnName) {
// return getInt(getColumnIndexOrThrow(columnName)) == 1;
// }
// }
//
// Path: app/src/main/java/com/philliphsu/clock2/data/ObjectWithId.java
// public abstract class ObjectWithId {
// private long id;
//
// public final long getId() {
// return id;
// }
//
// public final void setId(long id) {
// this.id = id;
// }
//
// public final int getIntId() {
// return (int) id;
// }
// }
// Path: app/src/main/java/com/philliphsu/clock2/list/RecyclerViewFragment.java
import android.widget.TextView;
import com.philliphsu.clock2.BaseFragment;
import com.philliphsu.clock2.R;
import com.philliphsu.clock2.data.BaseItemCursor;
import com.philliphsu.clock2.data.ObjectWithId;
import butterknife.Bind;
import android.os.Bundle;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/*
* Copyright 2017 Phillip Hsu
*
* This file is part of ClockPlus.
*
* ClockPlus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ClockPlus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ClockPlus. If not, see <http://www.gnu.org/licenses/>.
*/
package com.philliphsu.clock2.list;
/**
* Created by Phillip Hsu on 7/26/2016.
*/
public abstract class RecyclerViewFragment<
T extends ObjectWithId,
VH extends BaseViewHolder<T>,
C extends BaseItemCursor<T>,
A extends BaseCursorAdapter<T, VH, C>>
|
extends BaseFragment implements
|
hosuaby/example-restful-project
|
src/main/java/io/hosuaby/restful/services/TeapotCommandService.java
|
// Path: src/main/java/io/hosuaby/restful/controllers/TeapotCommandController.java
// @RestController
// @RequestMapping("/actions/teapots")
// public class TeapotCommandController {
//
// /** Teapot CRUD service */
// @Autowired
// private TeapotCrudService crud;
//
// /** Teapot command service */
// @Autowired
// private TeapotCommandService commandService;
//
// /** Port holder */
// @Autowired
// private PortHolder portHolder;
//
// @RequestMapping(
// value = "/{id}/startup",
// method = RequestMethod.POST)
// public void startup(@PathVariable String id)
// throws TeapotNotExistsException, URISyntaxException,
// DeploymentException, IOException {
//
// /* Get teapot */
// Teapot teapot = crud.find(id);
//
// /* Start teapot simulator */
// TeapotSimulator simulator = new TeapotSimulator(
// teapot, portHolder.getPort());
// }
//
// @RequestMapping(
// value = "/{id}/shutdown",
// method = RequestMethod.POST)
// public void shutdown(@PathVariable String id)
// throws IOException, TeapotNotConnectedException {
// commandService.shutdown(id);
// }
//
// @RequestMapping(
// value = "/{teapotId}/cli",
// method = RequestMethod.POST)
// public DeferredResult<String> executeCommand(
// @PathVariable String teapotId,
// @RequestParam(required = true) String cmd,
// HttpServletRequest req) throws IOException {
// return commandService.sendMessage(req, teapotId, cmd);
// }
//
// }
//
// Path: src/main/java/io/hosuaby/restful/services/exceptions/teapots/TeapotNotConnectedException.java
// public class TeapotNotConnectedException extends Exception {
//
// /**
// * When teapot with defined id not exists.
// */
// private static final String ERR_TEAPOT_NOT_CONNECTED = "Teapot with id \"%s\" not connected to server";
//
// /**
// * Serial ID.
// */
// private static final long serialVersionUID = 3484631448010563705L;
//
// /**
// * Constructor from teapot id.
// *
// * @param teapotId teapot id
// */
// public TeapotNotConnectedException(String teapotId) {
// super(String.format(ERR_TEAPOT_NOT_CONNECTED, teapotId));
// }
//
// }
|
import io.hosuaby.restful.controllers.TeapotCommandController;
import io.hosuaby.restful.services.exceptions.teapots.TeapotNotConnectedException;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.request.async.DeferredResult;
import org.springframework.web.socket.WebSocketSession;
|
package io.hosuaby.restful.services;
/**
* Service that provides registration of teapots and communication with them via
* web socket sessions.
*/
public interface TeapotCommandService {
/**
* Registers a newly connected teapot with associated websocket connection.
*
* @param teapotId teapot id
* @param session teapot websocket session
*/
void register(String teapotId, WebSocketSession session);
/**
* Unregisters disconnected teapot. This method don't close teapot session.
* Teapot session must be closed prior to call of this method. Teapot must
* be registered prior to call of this method.
*
* @param teapotSession teapot websocket session
*/
void unregister(WebSocketSession teapotSession);
/**
* Shutdown the connected teapot. This method is called by
* {@link TeapotCommandController}.
*
* @param teapotId teapot id.
*
* @throws IOException
* failed to close teapot session
* @throws TeapotNotConnectedException
* teapot with defined id is not connected
*/
void shutdown(String teapotId) throws IOException,
|
// Path: src/main/java/io/hosuaby/restful/controllers/TeapotCommandController.java
// @RestController
// @RequestMapping("/actions/teapots")
// public class TeapotCommandController {
//
// /** Teapot CRUD service */
// @Autowired
// private TeapotCrudService crud;
//
// /** Teapot command service */
// @Autowired
// private TeapotCommandService commandService;
//
// /** Port holder */
// @Autowired
// private PortHolder portHolder;
//
// @RequestMapping(
// value = "/{id}/startup",
// method = RequestMethod.POST)
// public void startup(@PathVariable String id)
// throws TeapotNotExistsException, URISyntaxException,
// DeploymentException, IOException {
//
// /* Get teapot */
// Teapot teapot = crud.find(id);
//
// /* Start teapot simulator */
// TeapotSimulator simulator = new TeapotSimulator(
// teapot, portHolder.getPort());
// }
//
// @RequestMapping(
// value = "/{id}/shutdown",
// method = RequestMethod.POST)
// public void shutdown(@PathVariable String id)
// throws IOException, TeapotNotConnectedException {
// commandService.shutdown(id);
// }
//
// @RequestMapping(
// value = "/{teapotId}/cli",
// method = RequestMethod.POST)
// public DeferredResult<String> executeCommand(
// @PathVariable String teapotId,
// @RequestParam(required = true) String cmd,
// HttpServletRequest req) throws IOException {
// return commandService.sendMessage(req, teapotId, cmd);
// }
//
// }
//
// Path: src/main/java/io/hosuaby/restful/services/exceptions/teapots/TeapotNotConnectedException.java
// public class TeapotNotConnectedException extends Exception {
//
// /**
// * When teapot with defined id not exists.
// */
// private static final String ERR_TEAPOT_NOT_CONNECTED = "Teapot with id \"%s\" not connected to server";
//
// /**
// * Serial ID.
// */
// private static final long serialVersionUID = 3484631448010563705L;
//
// /**
// * Constructor from teapot id.
// *
// * @param teapotId teapot id
// */
// public TeapotNotConnectedException(String teapotId) {
// super(String.format(ERR_TEAPOT_NOT_CONNECTED, teapotId));
// }
//
// }
// Path: src/main/java/io/hosuaby/restful/services/TeapotCommandService.java
import io.hosuaby.restful.controllers.TeapotCommandController;
import io.hosuaby.restful.services.exceptions.teapots.TeapotNotConnectedException;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.request.async.DeferredResult;
import org.springframework.web.socket.WebSocketSession;
package io.hosuaby.restful.services;
/**
* Service that provides registration of teapots and communication with them via
* web socket sessions.
*/
public interface TeapotCommandService {
/**
* Registers a newly connected teapot with associated websocket connection.
*
* @param teapotId teapot id
* @param session teapot websocket session
*/
void register(String teapotId, WebSocketSession session);
/**
* Unregisters disconnected teapot. This method don't close teapot session.
* Teapot session must be closed prior to call of this method. Teapot must
* be registered prior to call of this method.
*
* @param teapotSession teapot websocket session
*/
void unregister(WebSocketSession teapotSession);
/**
* Shutdown the connected teapot. This method is called by
* {@link TeapotCommandController}.
*
* @param teapotId teapot id.
*
* @throws IOException
* failed to close teapot session
* @throws TeapotNotConnectedException
* teapot with defined id is not connected
*/
void shutdown(String teapotId) throws IOException,
|
TeapotNotConnectedException;
|
hosuaby/example-restful-project
|
src/main/java/io/hosuaby/restful/services/exceptions/teapots/TeapotNotExistsException.java
|
// Path: src/main/java/io/hosuaby/restful/domain/Teapot.java
// @Document(collection = "teapots")
// public class Teapot {
//
// /** 0.3 L */
// public static final float L0_3 = (float) 0.3;
//
// /** 0.5 L */
// public static final float L0_5 = (float) 0.5;
//
// /** 1 L */
// public static final float L1 = (float) 1.0;
//
// /** 1.5 L */
// public static final float L1_5 = (float) 1.5;
//
// /** 3 L */
// public static final float L3 = (float) 3.0;
//
// /** 5 L */
// public static final float L5 = (float) 5.0;
//
// /** 8 L */
// public static final float L8 = (float) 8.0;
//
// /** 10 L */
// public static final float L10 = (float) 10.0;
//
// /** Id: valid id */
// private String id;
//
// /** Name: any String */
// private String name;
//
// /** Brand: any String */
// private String brand;
//
// /** Volume: from defined values */
// private float volume;
//
// /** Current IP address. Must be hidden from the web user */
// private Inet4Address ip;
//
// public Teapot() {
// super();
// }
//
// public Teapot(String id, String name, String brand, float volume) {
// super();
// this.id = id;
// this.name = name;
// this.brand = brand;
// this.volume = volume;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getBrand() {
// return brand;
// }
//
// public void setBrand(String brand) {
// this.brand = brand;
// }
//
// public float getVolume() {
// return volume;
// }
//
// public void setVolume(float volume) {
// this.volume = volume;
// }
//
// public Inet4Address getIp() {
// return ip;
// }
//
// public void setIp(Inet4Address ip) {
// this.ip = ip;
// }
//
// }
|
import io.hosuaby.restful.domain.Teapot;
|
package io.hosuaby.restful.services.exceptions.teapots;
/**
* Exception thrown when asked teapot doesn't exist.
*/
public class TeapotNotExistsException extends Exception {
/**
* When teapot with defined id not exists.
*/
private static final String ERR_TEAPOT_WITH_ID_NOT_EXISTS = "Teapot with id \"%s\" not exists";
/**
* When defined {@link Teapot} not exists.
*/
private static final String ERR_THIS_TEAPOT_NOT_EXISTS = "This teapot not exists";
/**
* Serial ID.
*/
private static final long serialVersionUID = 7839587611390496077L;
/**
* Constructor from teapot id.
*
* @param teapotId teapot id
*/
public TeapotNotExistsException(String teapotId) {
super(String.format(ERR_TEAPOT_WITH_ID_NOT_EXISTS, teapotId));
}
/**
* Constructor from {@link Teapot}.
*
* @param teapot teapot object
*/
|
// Path: src/main/java/io/hosuaby/restful/domain/Teapot.java
// @Document(collection = "teapots")
// public class Teapot {
//
// /** 0.3 L */
// public static final float L0_3 = (float) 0.3;
//
// /** 0.5 L */
// public static final float L0_5 = (float) 0.5;
//
// /** 1 L */
// public static final float L1 = (float) 1.0;
//
// /** 1.5 L */
// public static final float L1_5 = (float) 1.5;
//
// /** 3 L */
// public static final float L3 = (float) 3.0;
//
// /** 5 L */
// public static final float L5 = (float) 5.0;
//
// /** 8 L */
// public static final float L8 = (float) 8.0;
//
// /** 10 L */
// public static final float L10 = (float) 10.0;
//
// /** Id: valid id */
// private String id;
//
// /** Name: any String */
// private String name;
//
// /** Brand: any String */
// private String brand;
//
// /** Volume: from defined values */
// private float volume;
//
// /** Current IP address. Must be hidden from the web user */
// private Inet4Address ip;
//
// public Teapot() {
// super();
// }
//
// public Teapot(String id, String name, String brand, float volume) {
// super();
// this.id = id;
// this.name = name;
// this.brand = brand;
// this.volume = volume;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getBrand() {
// return brand;
// }
//
// public void setBrand(String brand) {
// this.brand = brand;
// }
//
// public float getVolume() {
// return volume;
// }
//
// public void setVolume(float volume) {
// this.volume = volume;
// }
//
// public Inet4Address getIp() {
// return ip;
// }
//
// public void setIp(Inet4Address ip) {
// this.ip = ip;
// }
//
// }
// Path: src/main/java/io/hosuaby/restful/services/exceptions/teapots/TeapotNotExistsException.java
import io.hosuaby.restful.domain.Teapot;
package io.hosuaby.restful.services.exceptions.teapots;
/**
* Exception thrown when asked teapot doesn't exist.
*/
public class TeapotNotExistsException extends Exception {
/**
* When teapot with defined id not exists.
*/
private static final String ERR_TEAPOT_WITH_ID_NOT_EXISTS = "Teapot with id \"%s\" not exists";
/**
* When defined {@link Teapot} not exists.
*/
private static final String ERR_THIS_TEAPOT_NOT_EXISTS = "This teapot not exists";
/**
* Serial ID.
*/
private static final long serialVersionUID = 7839587611390496077L;
/**
* Constructor from teapot id.
*
* @param teapotId teapot id
*/
public TeapotNotExistsException(String teapotId) {
super(String.format(ERR_TEAPOT_WITH_ID_NOT_EXISTS, teapotId));
}
/**
* Constructor from {@link Teapot}.
*
* @param teapot teapot object
*/
|
public TeapotNotExistsException(Teapot teapot) {
|
hosuaby/example-restful-project
|
src/main/java/io/hosuaby/restful/domain/validators/TeapotValidator.java
|
// Path: src/main/java/io/hosuaby/restful/domain/Teapot.java
// @Document(collection = "teapots")
// public class Teapot {
//
// /** 0.3 L */
// public static final float L0_3 = (float) 0.3;
//
// /** 0.5 L */
// public static final float L0_5 = (float) 0.5;
//
// /** 1 L */
// public static final float L1 = (float) 1.0;
//
// /** 1.5 L */
// public static final float L1_5 = (float) 1.5;
//
// /** 3 L */
// public static final float L3 = (float) 3.0;
//
// /** 5 L */
// public static final float L5 = (float) 5.0;
//
// /** 8 L */
// public static final float L8 = (float) 8.0;
//
// /** 10 L */
// public static final float L10 = (float) 10.0;
//
// /** Id: valid id */
// private String id;
//
// /** Name: any String */
// private String name;
//
// /** Brand: any String */
// private String brand;
//
// /** Volume: from defined values */
// private float volume;
//
// /** Current IP address. Must be hidden from the web user */
// private Inet4Address ip;
//
// public Teapot() {
// super();
// }
//
// public Teapot(String id, String name, String brand, float volume) {
// super();
// this.id = id;
// this.name = name;
// this.brand = brand;
// this.volume = volume;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getBrand() {
// return brand;
// }
//
// public void setBrand(String brand) {
// this.brand = brand;
// }
//
// public float getVolume() {
// return volume;
// }
//
// public void setVolume(float volume) {
// this.volume = volume;
// }
//
// public Inet4Address getIp() {
// return ip;
// }
//
// public void setIp(Inet4Address ip) {
// this.ip = ip;
// }
//
// }
|
import io.hosuaby.restful.domain.Teapot;
import java.util.Arrays;
import java.util.regex.Pattern;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;
|
package io.hosuaby.restful.domain.validators;
/**
* Teapot validator.
*/
@Component
public class TeapotValidator implements Validator {
/**
* Pattern for teapot id. Id must start with letter and can contain letter,
* digits and "_" character.
*/
private static final Pattern ID_PATTERN = Pattern.compile("[a-zA-Z]\\w*");
/**
* Valid teapot volumes.
*/
private static final Float[] VALID_VOLUMES = new Float[] {
|
// Path: src/main/java/io/hosuaby/restful/domain/Teapot.java
// @Document(collection = "teapots")
// public class Teapot {
//
// /** 0.3 L */
// public static final float L0_3 = (float) 0.3;
//
// /** 0.5 L */
// public static final float L0_5 = (float) 0.5;
//
// /** 1 L */
// public static final float L1 = (float) 1.0;
//
// /** 1.5 L */
// public static final float L1_5 = (float) 1.5;
//
// /** 3 L */
// public static final float L3 = (float) 3.0;
//
// /** 5 L */
// public static final float L5 = (float) 5.0;
//
// /** 8 L */
// public static final float L8 = (float) 8.0;
//
// /** 10 L */
// public static final float L10 = (float) 10.0;
//
// /** Id: valid id */
// private String id;
//
// /** Name: any String */
// private String name;
//
// /** Brand: any String */
// private String brand;
//
// /** Volume: from defined values */
// private float volume;
//
// /** Current IP address. Must be hidden from the web user */
// private Inet4Address ip;
//
// public Teapot() {
// super();
// }
//
// public Teapot(String id, String name, String brand, float volume) {
// super();
// this.id = id;
// this.name = name;
// this.brand = brand;
// this.volume = volume;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getBrand() {
// return brand;
// }
//
// public void setBrand(String brand) {
// this.brand = brand;
// }
//
// public float getVolume() {
// return volume;
// }
//
// public void setVolume(float volume) {
// this.volume = volume;
// }
//
// public Inet4Address getIp() {
// return ip;
// }
//
// public void setIp(Inet4Address ip) {
// this.ip = ip;
// }
//
// }
// Path: src/main/java/io/hosuaby/restful/domain/validators/TeapotValidator.java
import io.hosuaby.restful.domain.Teapot;
import java.util.Arrays;
import java.util.regex.Pattern;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;
package io.hosuaby.restful.domain.validators;
/**
* Teapot validator.
*/
@Component
public class TeapotValidator implements Validator {
/**
* Pattern for teapot id. Id must start with letter and can contain letter,
* digits and "_" character.
*/
private static final Pattern ID_PATTERN = Pattern.compile("[a-zA-Z]\\w*");
/**
* Valid teapot volumes.
*/
private static final Float[] VALID_VOLUMES = new Float[] {
|
Teapot.L0_3, Teapot.L0_5, Teapot.L1, Teapot.L1_5, Teapot.L3, Teapot.L5,
|
hosuaby/example-restful-project
|
src/main/java/io/hosuaby/restful/services/exceptions/teapots/TeapotsAlreadyExistException.java
|
// Path: src/main/java/io/hosuaby/restful/domain/Teapot.java
// @Document(collection = "teapots")
// public class Teapot {
//
// /** 0.3 L */
// public static final float L0_3 = (float) 0.3;
//
// /** 0.5 L */
// public static final float L0_5 = (float) 0.5;
//
// /** 1 L */
// public static final float L1 = (float) 1.0;
//
// /** 1.5 L */
// public static final float L1_5 = (float) 1.5;
//
// /** 3 L */
// public static final float L3 = (float) 3.0;
//
// /** 5 L */
// public static final float L5 = (float) 5.0;
//
// /** 8 L */
// public static final float L8 = (float) 8.0;
//
// /** 10 L */
// public static final float L10 = (float) 10.0;
//
// /** Id: valid id */
// private String id;
//
// /** Name: any String */
// private String name;
//
// /** Brand: any String */
// private String brand;
//
// /** Volume: from defined values */
// private float volume;
//
// /** Current IP address. Must be hidden from the web user */
// private Inet4Address ip;
//
// public Teapot() {
// super();
// }
//
// public Teapot(String id, String name, String brand, float volume) {
// super();
// this.id = id;
// this.name = name;
// this.brand = brand;
// this.volume = volume;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getBrand() {
// return brand;
// }
//
// public void setBrand(String brand) {
// this.brand = brand;
// }
//
// public float getVolume() {
// return volume;
// }
//
// public void setVolume(float volume) {
// this.volume = volume;
// }
//
// public Inet4Address getIp() {
// return ip;
// }
//
// public void setIp(Inet4Address ip) {
// this.ip = ip;
// }
//
// }
|
import io.hosuaby.restful.domain.Teapot;
import java.util.Collection;
import java.util.stream.Stream;
|
package io.hosuaby.restful.services.exceptions.teapots;
/**
* Exception thrown when user tries to add teapots that already exist.
*/
public class TeapotsAlreadyExistException extends Exception {
/**
* When teapots with defined ids already exist.
*/
private static final String ERR_TEAPOTS_WITH_IDS_ALREADY_EXIST = "Teapots with folowing ids already exist";
/**
* When defined {@link Teapot} objects already exist.
*/
private static final String ERR_THOSE_TEAPOTS_ALREADY_EXIST = "Those teapots already exist";
/**
* Serial ID.
*/
private static final long serialVersionUID = 4483120563431775221L;
/**
* Constructor from collection of teapot ids.
*
* @param ids teapot ids
*/
public TeapotsAlreadyExistException(Collection<String> ids) {
super(ERR_TEAPOTS_WITH_IDS_ALREADY_EXIST + ": " + String.join(", ", ids));
}
/**
* Constructor from iterable with {@link Teapot} objects.
*
* @param teapots iterable with teapot objects
*/
|
// Path: src/main/java/io/hosuaby/restful/domain/Teapot.java
// @Document(collection = "teapots")
// public class Teapot {
//
// /** 0.3 L */
// public static final float L0_3 = (float) 0.3;
//
// /** 0.5 L */
// public static final float L0_5 = (float) 0.5;
//
// /** 1 L */
// public static final float L1 = (float) 1.0;
//
// /** 1.5 L */
// public static final float L1_5 = (float) 1.5;
//
// /** 3 L */
// public static final float L3 = (float) 3.0;
//
// /** 5 L */
// public static final float L5 = (float) 5.0;
//
// /** 8 L */
// public static final float L8 = (float) 8.0;
//
// /** 10 L */
// public static final float L10 = (float) 10.0;
//
// /** Id: valid id */
// private String id;
//
// /** Name: any String */
// private String name;
//
// /** Brand: any String */
// private String brand;
//
// /** Volume: from defined values */
// private float volume;
//
// /** Current IP address. Must be hidden from the web user */
// private Inet4Address ip;
//
// public Teapot() {
// super();
// }
//
// public Teapot(String id, String name, String brand, float volume) {
// super();
// this.id = id;
// this.name = name;
// this.brand = brand;
// this.volume = volume;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getBrand() {
// return brand;
// }
//
// public void setBrand(String brand) {
// this.brand = brand;
// }
//
// public float getVolume() {
// return volume;
// }
//
// public void setVolume(float volume) {
// this.volume = volume;
// }
//
// public Inet4Address getIp() {
// return ip;
// }
//
// public void setIp(Inet4Address ip) {
// this.ip = ip;
// }
//
// }
// Path: src/main/java/io/hosuaby/restful/services/exceptions/teapots/TeapotsAlreadyExistException.java
import io.hosuaby.restful.domain.Teapot;
import java.util.Collection;
import java.util.stream.Stream;
package io.hosuaby.restful.services.exceptions.teapots;
/**
* Exception thrown when user tries to add teapots that already exist.
*/
public class TeapotsAlreadyExistException extends Exception {
/**
* When teapots with defined ids already exist.
*/
private static final String ERR_TEAPOTS_WITH_IDS_ALREADY_EXIST = "Teapots with folowing ids already exist";
/**
* When defined {@link Teapot} objects already exist.
*/
private static final String ERR_THOSE_TEAPOTS_ALREADY_EXIST = "Those teapots already exist";
/**
* Serial ID.
*/
private static final long serialVersionUID = 4483120563431775221L;
/**
* Constructor from collection of teapot ids.
*
* @param ids teapot ids
*/
public TeapotsAlreadyExistException(Collection<String> ids) {
super(ERR_TEAPOTS_WITH_IDS_ALREADY_EXIST + ": " + String.join(", ", ids));
}
/**
* Constructor from iterable with {@link Teapot} objects.
*
* @param teapots iterable with teapot objects
*/
|
public TeapotsAlreadyExistException(Iterable<? extends Teapot> teapots) {
|
hosuaby/example-restful-project
|
src/main/java/io/hosuaby/restful/simulators/TeapotSimulator.java
|
// Path: src/main/java/io/hosuaby/restful/domain/Teapot.java
// @Document(collection = "teapots")
// public class Teapot {
//
// /** 0.3 L */
// public static final float L0_3 = (float) 0.3;
//
// /** 0.5 L */
// public static final float L0_5 = (float) 0.5;
//
// /** 1 L */
// public static final float L1 = (float) 1.0;
//
// /** 1.5 L */
// public static final float L1_5 = (float) 1.5;
//
// /** 3 L */
// public static final float L3 = (float) 3.0;
//
// /** 5 L */
// public static final float L5 = (float) 5.0;
//
// /** 8 L */
// public static final float L8 = (float) 8.0;
//
// /** 10 L */
// public static final float L10 = (float) 10.0;
//
// /** Id: valid id */
// private String id;
//
// /** Name: any String */
// private String name;
//
// /** Brand: any String */
// private String brand;
//
// /** Volume: from defined values */
// private float volume;
//
// /** Current IP address. Must be hidden from the web user */
// private Inet4Address ip;
//
// public Teapot() {
// super();
// }
//
// public Teapot(String id, String name, String brand, float volume) {
// super();
// this.id = id;
// this.name = name;
// this.brand = brand;
// this.volume = volume;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getBrand() {
// return brand;
// }
//
// public void setBrand(String brand) {
// this.brand = brand;
// }
//
// public float getVolume() {
// return volume;
// }
//
// public void setVolume(float volume) {
// this.volume = volume;
// }
//
// public Inet4Address getIp() {
// return ip;
// }
//
// public void setIp(Inet4Address ip) {
// this.ip = ip;
// }
//
// }
//
// Path: src/main/java/io/hosuaby/restful/domain/TeapotMessage.java
// public class TeapotMessage {
//
// /** Client id */
// private String clientId;
//
// /** Message payload */
// private String payload;
//
// public TeapotMessage() {
// super();
// }
//
// public TeapotMessage(String clientId, String payload) {
// super();
// this.clientId = clientId;
// this.payload = payload;
// }
//
// public String getClientId() {
// return clientId;
// }
//
// public void setClientId(String clientId) {
// this.clientId = clientId;
// }
//
// public String getPayload() {
// return payload;
// }
//
// public void setPayload(String payload) {
// this.payload = payload;
// }
//
// }
|
import io.hosuaby.restful.domain.Teapot;
import io.hosuaby.restful.domain.TeapotMessage;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.websocket.ClientEndpointConfig;
import javax.websocket.CloseReason;
import javax.websocket.ContainerProvider;
import javax.websocket.DeploymentException;
import javax.websocket.Endpoint;
import javax.websocket.EndpointConfig;
import javax.websocket.MessageHandler;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;
import com.fasterxml.jackson.databind.ObjectMapper;
|
/**
* Handler for incoming messages.
*/
private static class TeapotSimulatorMessageHandler
implements MessageHandler.Whole<String> {
/** Teapot simulator object */
private TeapotSimulator simulator;
/** Websocket session */
private Session session;
/**
* Constructor from simulator and websocket session.
*
* @param simulator simulator object
* @param session websocket object
*/
public TeapotSimulatorMessageHandler(TeapotSimulator simulator,
Session session) {
this.simulator = simulator;
this.session = session;
}
/**
* Handler for incoming messages.
*/
@Override
public void onMessage(String message) {
|
// Path: src/main/java/io/hosuaby/restful/domain/Teapot.java
// @Document(collection = "teapots")
// public class Teapot {
//
// /** 0.3 L */
// public static final float L0_3 = (float) 0.3;
//
// /** 0.5 L */
// public static final float L0_5 = (float) 0.5;
//
// /** 1 L */
// public static final float L1 = (float) 1.0;
//
// /** 1.5 L */
// public static final float L1_5 = (float) 1.5;
//
// /** 3 L */
// public static final float L3 = (float) 3.0;
//
// /** 5 L */
// public static final float L5 = (float) 5.0;
//
// /** 8 L */
// public static final float L8 = (float) 8.0;
//
// /** 10 L */
// public static final float L10 = (float) 10.0;
//
// /** Id: valid id */
// private String id;
//
// /** Name: any String */
// private String name;
//
// /** Brand: any String */
// private String brand;
//
// /** Volume: from defined values */
// private float volume;
//
// /** Current IP address. Must be hidden from the web user */
// private Inet4Address ip;
//
// public Teapot() {
// super();
// }
//
// public Teapot(String id, String name, String brand, float volume) {
// super();
// this.id = id;
// this.name = name;
// this.brand = brand;
// this.volume = volume;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getBrand() {
// return brand;
// }
//
// public void setBrand(String brand) {
// this.brand = brand;
// }
//
// public float getVolume() {
// return volume;
// }
//
// public void setVolume(float volume) {
// this.volume = volume;
// }
//
// public Inet4Address getIp() {
// return ip;
// }
//
// public void setIp(Inet4Address ip) {
// this.ip = ip;
// }
//
// }
//
// Path: src/main/java/io/hosuaby/restful/domain/TeapotMessage.java
// public class TeapotMessage {
//
// /** Client id */
// private String clientId;
//
// /** Message payload */
// private String payload;
//
// public TeapotMessage() {
// super();
// }
//
// public TeapotMessage(String clientId, String payload) {
// super();
// this.clientId = clientId;
// this.payload = payload;
// }
//
// public String getClientId() {
// return clientId;
// }
//
// public void setClientId(String clientId) {
// this.clientId = clientId;
// }
//
// public String getPayload() {
// return payload;
// }
//
// public void setPayload(String payload) {
// this.payload = payload;
// }
//
// }
// Path: src/main/java/io/hosuaby/restful/simulators/TeapotSimulator.java
import io.hosuaby.restful.domain.Teapot;
import io.hosuaby.restful.domain.TeapotMessage;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.websocket.ClientEndpointConfig;
import javax.websocket.CloseReason;
import javax.websocket.ContainerProvider;
import javax.websocket.DeploymentException;
import javax.websocket.Endpoint;
import javax.websocket.EndpointConfig;
import javax.websocket.MessageHandler;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* Handler for incoming messages.
*/
private static class TeapotSimulatorMessageHandler
implements MessageHandler.Whole<String> {
/** Teapot simulator object */
private TeapotSimulator simulator;
/** Websocket session */
private Session session;
/**
* Constructor from simulator and websocket session.
*
* @param simulator simulator object
* @param session websocket object
*/
public TeapotSimulatorMessageHandler(TeapotSimulator simulator,
Session session) {
this.simulator = simulator;
this.session = session;
}
/**
* Handler for incoming messages.
*/
@Override
public void onMessage(String message) {
|
TeapotMessage msg;
|
hosuaby/example-restful-project
|
src/main/java/io/hosuaby/restful/services/TeapotCommandServiceImpl.java
|
// Path: src/main/java/io/hosuaby/restful/domain/TeapotMessage.java
// public class TeapotMessage {
//
// /** Client id */
// private String clientId;
//
// /** Message payload */
// private String payload;
//
// public TeapotMessage() {
// super();
// }
//
// public TeapotMessage(String clientId, String payload) {
// super();
// this.clientId = clientId;
// this.payload = payload;
// }
//
// public String getClientId() {
// return clientId;
// }
//
// public void setClientId(String clientId) {
// this.clientId = clientId;
// }
//
// public String getPayload() {
// return payload;
// }
//
// public void setPayload(String payload) {
// this.payload = payload;
// }
//
// }
//
// Path: src/main/java/io/hosuaby/restful/repositories/WebSocketSessionRepository.java
// public class WebSocketSessionRepository {
//
// /**
// * Sessions store.
// */
// private Map<String, WebSocketSession> sessions;
//
// /**
// * Creates an instance backed by a {@link ConcurrentHashMap}
// */
// public WebSocketSessionRepository() {
// sessions = new HashMap<>(); // not thread safe HashMap
// }
//
// /**
// * Saves the session. If session was already registered method does nothing.
// *
// * @param session web socket session
// */
// public void save(WebSocketSession session) {
// sessions.put(session.getId(), session);
// }
//
// /**
// * Returns all websocket sessions from this repository.
// *
// * @return collection of websocket sessions
// */
// public Collection<WebSocketSession> getSessions() {
// return sessions.values();
// }
//
// /**
// * Returns the session by it's id.
// *
// * @param id session id
// *
// * @return websocket session, if no session was found returns null.
// */
// public WebSocketSession getSession(String id) {
// return sessions.get(id);
// }
//
// /**
// * Deletes the session with defined id. If not session with this id was
// * defined, method does nothing.
// *
// * @param id session id
// */
// public void delete(String id) {
// sessions.remove(id);
// }
//
// /**
// * Deletes the session. If defined session was not found, method does
// * nothing.
// *
// * @param session websocket session
// */
// public void delete(WebSocketSession session) {
// sessions.remove(session.getId());
// }
//
// }
//
// Path: src/main/java/io/hosuaby/restful/services/exceptions/teapots/TeapotInternalErrorException.java
// public class TeapotInternalErrorException extends Exception {
//
// /**
// * Serial ID.
// */
// private static final long serialVersionUID = 5083886954829581207L;
//
// /**
// * Constructor from error message.
// *
// * @param error error message
// */
// public TeapotInternalErrorException(String error) {
// super(error);
// }
// }
//
// Path: src/main/java/io/hosuaby/restful/services/exceptions/teapots/TeapotNotConnectedException.java
// public class TeapotNotConnectedException extends Exception {
//
// /**
// * When teapot with defined id not exists.
// */
// private static final String ERR_TEAPOT_NOT_CONNECTED = "Teapot with id \"%s\" not connected to server";
//
// /**
// * Serial ID.
// */
// private static final long serialVersionUID = 3484631448010563705L;
//
// /**
// * Constructor from teapot id.
// *
// * @param teapotId teapot id
// */
// public TeapotNotConnectedException(String teapotId) {
// super(String.format(ERR_TEAPOT_NOT_CONNECTED, teapotId));
// }
//
// }
|
import io.hosuaby.restful.domain.TeapotMessage;
import io.hosuaby.restful.repositories.WebSocketSessionRepository;
import io.hosuaby.restful.services.exceptions.teapots.TeapotInternalErrorException;
import io.hosuaby.restful.services.exceptions.teapots.TeapotNotConnectedException;
import java.io.IOException;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.async.DeferredResult;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import com.fasterxml.jackson.databind.ObjectMapper;
|
package io.hosuaby.restful.services;
/**
* Implementation of the {@link TeapotCommandService}.
*/
@Service
// TODO: implement appropriate thread synchronization
public class TeapotCommandServiceImpl implements TeapotCommandService {
/**
* Pattern for request id. Id must start with sequence "req-".
*/
private static final Pattern REQUEST_ID_PATTERN = Pattern.compile("^req-.*");
/** Repository for websocket sessions of teapots */
@Autowired
@Qualifier("teapotSessionsRepository")
|
// Path: src/main/java/io/hosuaby/restful/domain/TeapotMessage.java
// public class TeapotMessage {
//
// /** Client id */
// private String clientId;
//
// /** Message payload */
// private String payload;
//
// public TeapotMessage() {
// super();
// }
//
// public TeapotMessage(String clientId, String payload) {
// super();
// this.clientId = clientId;
// this.payload = payload;
// }
//
// public String getClientId() {
// return clientId;
// }
//
// public void setClientId(String clientId) {
// this.clientId = clientId;
// }
//
// public String getPayload() {
// return payload;
// }
//
// public void setPayload(String payload) {
// this.payload = payload;
// }
//
// }
//
// Path: src/main/java/io/hosuaby/restful/repositories/WebSocketSessionRepository.java
// public class WebSocketSessionRepository {
//
// /**
// * Sessions store.
// */
// private Map<String, WebSocketSession> sessions;
//
// /**
// * Creates an instance backed by a {@link ConcurrentHashMap}
// */
// public WebSocketSessionRepository() {
// sessions = new HashMap<>(); // not thread safe HashMap
// }
//
// /**
// * Saves the session. If session was already registered method does nothing.
// *
// * @param session web socket session
// */
// public void save(WebSocketSession session) {
// sessions.put(session.getId(), session);
// }
//
// /**
// * Returns all websocket sessions from this repository.
// *
// * @return collection of websocket sessions
// */
// public Collection<WebSocketSession> getSessions() {
// return sessions.values();
// }
//
// /**
// * Returns the session by it's id.
// *
// * @param id session id
// *
// * @return websocket session, if no session was found returns null.
// */
// public WebSocketSession getSession(String id) {
// return sessions.get(id);
// }
//
// /**
// * Deletes the session with defined id. If not session with this id was
// * defined, method does nothing.
// *
// * @param id session id
// */
// public void delete(String id) {
// sessions.remove(id);
// }
//
// /**
// * Deletes the session. If defined session was not found, method does
// * nothing.
// *
// * @param session websocket session
// */
// public void delete(WebSocketSession session) {
// sessions.remove(session.getId());
// }
//
// }
//
// Path: src/main/java/io/hosuaby/restful/services/exceptions/teapots/TeapotInternalErrorException.java
// public class TeapotInternalErrorException extends Exception {
//
// /**
// * Serial ID.
// */
// private static final long serialVersionUID = 5083886954829581207L;
//
// /**
// * Constructor from error message.
// *
// * @param error error message
// */
// public TeapotInternalErrorException(String error) {
// super(error);
// }
// }
//
// Path: src/main/java/io/hosuaby/restful/services/exceptions/teapots/TeapotNotConnectedException.java
// public class TeapotNotConnectedException extends Exception {
//
// /**
// * When teapot with defined id not exists.
// */
// private static final String ERR_TEAPOT_NOT_CONNECTED = "Teapot with id \"%s\" not connected to server";
//
// /**
// * Serial ID.
// */
// private static final long serialVersionUID = 3484631448010563705L;
//
// /**
// * Constructor from teapot id.
// *
// * @param teapotId teapot id
// */
// public TeapotNotConnectedException(String teapotId) {
// super(String.format(ERR_TEAPOT_NOT_CONNECTED, teapotId));
// }
//
// }
// Path: src/main/java/io/hosuaby/restful/services/TeapotCommandServiceImpl.java
import io.hosuaby.restful.domain.TeapotMessage;
import io.hosuaby.restful.repositories.WebSocketSessionRepository;
import io.hosuaby.restful.services.exceptions.teapots.TeapotInternalErrorException;
import io.hosuaby.restful.services.exceptions.teapots.TeapotNotConnectedException;
import java.io.IOException;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.async.DeferredResult;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import com.fasterxml.jackson.databind.ObjectMapper;
package io.hosuaby.restful.services;
/**
* Implementation of the {@link TeapotCommandService}.
*/
@Service
// TODO: implement appropriate thread synchronization
public class TeapotCommandServiceImpl implements TeapotCommandService {
/**
* Pattern for request id. Id must start with sequence "req-".
*/
private static final Pattern REQUEST_ID_PATTERN = Pattern.compile("^req-.*");
/** Repository for websocket sessions of teapots */
@Autowired
@Qualifier("teapotSessionsRepository")
|
private WebSocketSessionRepository sessionRepository;
|
hosuaby/example-restful-project
|
src/main/java/io/hosuaby/restful/services/exceptions/teapots/TeapotsNotExistException.java
|
// Path: src/main/java/io/hosuaby/restful/domain/Teapot.java
// @Document(collection = "teapots")
// public class Teapot {
//
// /** 0.3 L */
// public static final float L0_3 = (float) 0.3;
//
// /** 0.5 L */
// public static final float L0_5 = (float) 0.5;
//
// /** 1 L */
// public static final float L1 = (float) 1.0;
//
// /** 1.5 L */
// public static final float L1_5 = (float) 1.5;
//
// /** 3 L */
// public static final float L3 = (float) 3.0;
//
// /** 5 L */
// public static final float L5 = (float) 5.0;
//
// /** 8 L */
// public static final float L8 = (float) 8.0;
//
// /** 10 L */
// public static final float L10 = (float) 10.0;
//
// /** Id: valid id */
// private String id;
//
// /** Name: any String */
// private String name;
//
// /** Brand: any String */
// private String brand;
//
// /** Volume: from defined values */
// private float volume;
//
// /** Current IP address. Must be hidden from the web user */
// private Inet4Address ip;
//
// public Teapot() {
// super();
// }
//
// public Teapot(String id, String name, String brand, float volume) {
// super();
// this.id = id;
// this.name = name;
// this.brand = brand;
// this.volume = volume;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getBrand() {
// return brand;
// }
//
// public void setBrand(String brand) {
// this.brand = brand;
// }
//
// public float getVolume() {
// return volume;
// }
//
// public void setVolume(float volume) {
// this.volume = volume;
// }
//
// public Inet4Address getIp() {
// return ip;
// }
//
// public void setIp(Inet4Address ip) {
// this.ip = ip;
// }
//
// }
|
import io.hosuaby.restful.domain.Teapot;
import java.util.Collection;
import java.util.stream.Stream;
|
package io.hosuaby.restful.services.exceptions.teapots;
/**
* Exception thrown when one or many asked teapots not exist.
*/
public class TeapotsNotExistException extends Exception {
/**
* When teapots with defined ids not exist.
*/
private static final String ERR_TEAPOTS_WITH_IDS_NOT_EXISTS = "Teapots with folowing ids not exist";
/**
* When defined {@link Teapot} objects not exist.
*/
private static final String ERR_THOSE_TEAPOTS_NOT_EXIST = "Those teapots not exist";
/**
* Serial ID.
*/
private static final long serialVersionUID = 3290080700826331780L;
/**
* Constructor from collection of teapot ids.
*
* @param ids teapot ids
*/
public TeapotsNotExistException(Collection<String> ids) {
super(ERR_TEAPOTS_WITH_IDS_NOT_EXISTS + ": " + String.join(", ", ids));
}
/**
* Constructor from iterable with {@link Teapot} objects.
*
* @param teapots iterable with teapot objects
*/
|
// Path: src/main/java/io/hosuaby/restful/domain/Teapot.java
// @Document(collection = "teapots")
// public class Teapot {
//
// /** 0.3 L */
// public static final float L0_3 = (float) 0.3;
//
// /** 0.5 L */
// public static final float L0_5 = (float) 0.5;
//
// /** 1 L */
// public static final float L1 = (float) 1.0;
//
// /** 1.5 L */
// public static final float L1_5 = (float) 1.5;
//
// /** 3 L */
// public static final float L3 = (float) 3.0;
//
// /** 5 L */
// public static final float L5 = (float) 5.0;
//
// /** 8 L */
// public static final float L8 = (float) 8.0;
//
// /** 10 L */
// public static final float L10 = (float) 10.0;
//
// /** Id: valid id */
// private String id;
//
// /** Name: any String */
// private String name;
//
// /** Brand: any String */
// private String brand;
//
// /** Volume: from defined values */
// private float volume;
//
// /** Current IP address. Must be hidden from the web user */
// private Inet4Address ip;
//
// public Teapot() {
// super();
// }
//
// public Teapot(String id, String name, String brand, float volume) {
// super();
// this.id = id;
// this.name = name;
// this.brand = brand;
// this.volume = volume;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getBrand() {
// return brand;
// }
//
// public void setBrand(String brand) {
// this.brand = brand;
// }
//
// public float getVolume() {
// return volume;
// }
//
// public void setVolume(float volume) {
// this.volume = volume;
// }
//
// public Inet4Address getIp() {
// return ip;
// }
//
// public void setIp(Inet4Address ip) {
// this.ip = ip;
// }
//
// }
// Path: src/main/java/io/hosuaby/restful/services/exceptions/teapots/TeapotsNotExistException.java
import io.hosuaby.restful.domain.Teapot;
import java.util.Collection;
import java.util.stream.Stream;
package io.hosuaby.restful.services.exceptions.teapots;
/**
* Exception thrown when one or many asked teapots not exist.
*/
public class TeapotsNotExistException extends Exception {
/**
* When teapots with defined ids not exist.
*/
private static final String ERR_TEAPOTS_WITH_IDS_NOT_EXISTS = "Teapots with folowing ids not exist";
/**
* When defined {@link Teapot} objects not exist.
*/
private static final String ERR_THOSE_TEAPOTS_NOT_EXIST = "Those teapots not exist";
/**
* Serial ID.
*/
private static final long serialVersionUID = 3290080700826331780L;
/**
* Constructor from collection of teapot ids.
*
* @param ids teapot ids
*/
public TeapotsNotExistException(Collection<String> ids) {
super(ERR_TEAPOTS_WITH_IDS_NOT_EXISTS + ": " + String.join(", ", ids));
}
/**
* Constructor from iterable with {@link Teapot} objects.
*
* @param teapots iterable with teapot objects
*/
|
public TeapotsNotExistException(Iterable<? extends Teapot> teapots) {
|
hosuaby/example-restful-project
|
src/main/java/io/hosuaby/restful/mappers/TeapotMapper.java
|
// Path: src/main/java/io/hosuaby/restful/domain/Teapot.java
// @Document(collection = "teapots")
// public class Teapot {
//
// /** 0.3 L */
// public static final float L0_3 = (float) 0.3;
//
// /** 0.5 L */
// public static final float L0_5 = (float) 0.5;
//
// /** 1 L */
// public static final float L1 = (float) 1.0;
//
// /** 1.5 L */
// public static final float L1_5 = (float) 1.5;
//
// /** 3 L */
// public static final float L3 = (float) 3.0;
//
// /** 5 L */
// public static final float L5 = (float) 5.0;
//
// /** 8 L */
// public static final float L8 = (float) 8.0;
//
// /** 10 L */
// public static final float L10 = (float) 10.0;
//
// /** Id: valid id */
// private String id;
//
// /** Name: any String */
// private String name;
//
// /** Brand: any String */
// private String brand;
//
// /** Volume: from defined values */
// private float volume;
//
// /** Current IP address. Must be hidden from the web user */
// private Inet4Address ip;
//
// public Teapot() {
// super();
// }
//
// public Teapot(String id, String name, String brand, float volume) {
// super();
// this.id = id;
// this.name = name;
// this.brand = brand;
// this.volume = volume;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getBrand() {
// return brand;
// }
//
// public void setBrand(String brand) {
// this.brand = brand;
// }
//
// public float getVolume() {
// return volume;
// }
//
// public void setVolume(float volume) {
// this.volume = volume;
// }
//
// public Inet4Address getIp() {
// return ip;
// }
//
// public void setIp(Inet4Address ip) {
// this.ip = ip;
// }
//
// }
//
// Path: src/main/java/io/hosuaby/restful/mappings/TeapotMapping.java
// public class TeapotMapping {
//
// /** Id: valid id */
// private String id;
//
// /** Name: any String */
// private String name;
//
// /** Brand: any String */
// private String brand;
//
// /** Volume: from defined values */
// private float volume;
//
// /** Current state of the teapot */
// private TeapotState state;
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getBrand() {
// return brand;
// }
//
// public void setBrand(String brand) {
// this.brand = brand;
// }
//
// public float getVolume() {
// return volume;
// }
//
// public void setVolume(float volume) {
// this.volume = volume;
// }
//
// public TeapotState getState() {
// return state;
// }
//
// public void setState(TeapotState state) {
// this.state = state;
// }
//
// }
//
// Path: src/main/java/io/hosuaby/restful/mappings/TeapotState.java
// public enum TeapotState {
//
// /** Teapot connected to the server and waiting for commands */
// IDLE,
//
// /** Teapot is not connected to the server */
// UNAVAILABLE
//
// }
|
import io.hosuaby.restful.domain.Teapot;
import io.hosuaby.restful.mappings.TeapotMapping;
import io.hosuaby.restful.mappings.TeapotState;
import java.util.Collection;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
|
package io.hosuaby.restful.mappers;
/**
* Mapper between {@link Teapot} and {@link TeapotMapping}.
*/
@Mapper(imports = TeapotState.class)
public abstract class TeapotMapper {
/**
* Creates mapping from teapot.
*
* @param teapot teapot
*
* @return teapot mapping
*/
@Mapping(
target = "state",
expression = "java("
+ "teapot.getIp() != null ? TeapotState.IDLE"
+ " : TeapotState.UNAVAILABLE"
+ ")")
|
// Path: src/main/java/io/hosuaby/restful/domain/Teapot.java
// @Document(collection = "teapots")
// public class Teapot {
//
// /** 0.3 L */
// public static final float L0_3 = (float) 0.3;
//
// /** 0.5 L */
// public static final float L0_5 = (float) 0.5;
//
// /** 1 L */
// public static final float L1 = (float) 1.0;
//
// /** 1.5 L */
// public static final float L1_5 = (float) 1.5;
//
// /** 3 L */
// public static final float L3 = (float) 3.0;
//
// /** 5 L */
// public static final float L5 = (float) 5.0;
//
// /** 8 L */
// public static final float L8 = (float) 8.0;
//
// /** 10 L */
// public static final float L10 = (float) 10.0;
//
// /** Id: valid id */
// private String id;
//
// /** Name: any String */
// private String name;
//
// /** Brand: any String */
// private String brand;
//
// /** Volume: from defined values */
// private float volume;
//
// /** Current IP address. Must be hidden from the web user */
// private Inet4Address ip;
//
// public Teapot() {
// super();
// }
//
// public Teapot(String id, String name, String brand, float volume) {
// super();
// this.id = id;
// this.name = name;
// this.brand = brand;
// this.volume = volume;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getBrand() {
// return brand;
// }
//
// public void setBrand(String brand) {
// this.brand = brand;
// }
//
// public float getVolume() {
// return volume;
// }
//
// public void setVolume(float volume) {
// this.volume = volume;
// }
//
// public Inet4Address getIp() {
// return ip;
// }
//
// public void setIp(Inet4Address ip) {
// this.ip = ip;
// }
//
// }
//
// Path: src/main/java/io/hosuaby/restful/mappings/TeapotMapping.java
// public class TeapotMapping {
//
// /** Id: valid id */
// private String id;
//
// /** Name: any String */
// private String name;
//
// /** Brand: any String */
// private String brand;
//
// /** Volume: from defined values */
// private float volume;
//
// /** Current state of the teapot */
// private TeapotState state;
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getBrand() {
// return brand;
// }
//
// public void setBrand(String brand) {
// this.brand = brand;
// }
//
// public float getVolume() {
// return volume;
// }
//
// public void setVolume(float volume) {
// this.volume = volume;
// }
//
// public TeapotState getState() {
// return state;
// }
//
// public void setState(TeapotState state) {
// this.state = state;
// }
//
// }
//
// Path: src/main/java/io/hosuaby/restful/mappings/TeapotState.java
// public enum TeapotState {
//
// /** Teapot connected to the server and waiting for commands */
// IDLE,
//
// /** Teapot is not connected to the server */
// UNAVAILABLE
//
// }
// Path: src/main/java/io/hosuaby/restful/mappers/TeapotMapper.java
import io.hosuaby.restful.domain.Teapot;
import io.hosuaby.restful.mappings.TeapotMapping;
import io.hosuaby.restful.mappings.TeapotState;
import java.util.Collection;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
package io.hosuaby.restful.mappers;
/**
* Mapper between {@link Teapot} and {@link TeapotMapping}.
*/
@Mapper(imports = TeapotState.class)
public abstract class TeapotMapper {
/**
* Creates mapping from teapot.
*
* @param teapot teapot
*
* @return teapot mapping
*/
@Mapping(
target = "state",
expression = "java("
+ "teapot.getIp() != null ? TeapotState.IDLE"
+ " : TeapotState.UNAVAILABLE"
+ ")")
|
public abstract TeapotMapping toMapping(Teapot teapot);
|
hosuaby/example-restful-project
|
src/main/java/io/hosuaby/restful/mappers/TeapotMapper.java
|
// Path: src/main/java/io/hosuaby/restful/domain/Teapot.java
// @Document(collection = "teapots")
// public class Teapot {
//
// /** 0.3 L */
// public static final float L0_3 = (float) 0.3;
//
// /** 0.5 L */
// public static final float L0_5 = (float) 0.5;
//
// /** 1 L */
// public static final float L1 = (float) 1.0;
//
// /** 1.5 L */
// public static final float L1_5 = (float) 1.5;
//
// /** 3 L */
// public static final float L3 = (float) 3.0;
//
// /** 5 L */
// public static final float L5 = (float) 5.0;
//
// /** 8 L */
// public static final float L8 = (float) 8.0;
//
// /** 10 L */
// public static final float L10 = (float) 10.0;
//
// /** Id: valid id */
// private String id;
//
// /** Name: any String */
// private String name;
//
// /** Brand: any String */
// private String brand;
//
// /** Volume: from defined values */
// private float volume;
//
// /** Current IP address. Must be hidden from the web user */
// private Inet4Address ip;
//
// public Teapot() {
// super();
// }
//
// public Teapot(String id, String name, String brand, float volume) {
// super();
// this.id = id;
// this.name = name;
// this.brand = brand;
// this.volume = volume;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getBrand() {
// return brand;
// }
//
// public void setBrand(String brand) {
// this.brand = brand;
// }
//
// public float getVolume() {
// return volume;
// }
//
// public void setVolume(float volume) {
// this.volume = volume;
// }
//
// public Inet4Address getIp() {
// return ip;
// }
//
// public void setIp(Inet4Address ip) {
// this.ip = ip;
// }
//
// }
//
// Path: src/main/java/io/hosuaby/restful/mappings/TeapotMapping.java
// public class TeapotMapping {
//
// /** Id: valid id */
// private String id;
//
// /** Name: any String */
// private String name;
//
// /** Brand: any String */
// private String brand;
//
// /** Volume: from defined values */
// private float volume;
//
// /** Current state of the teapot */
// private TeapotState state;
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getBrand() {
// return brand;
// }
//
// public void setBrand(String brand) {
// this.brand = brand;
// }
//
// public float getVolume() {
// return volume;
// }
//
// public void setVolume(float volume) {
// this.volume = volume;
// }
//
// public TeapotState getState() {
// return state;
// }
//
// public void setState(TeapotState state) {
// this.state = state;
// }
//
// }
//
// Path: src/main/java/io/hosuaby/restful/mappings/TeapotState.java
// public enum TeapotState {
//
// /** Teapot connected to the server and waiting for commands */
// IDLE,
//
// /** Teapot is not connected to the server */
// UNAVAILABLE
//
// }
|
import io.hosuaby.restful.domain.Teapot;
import io.hosuaby.restful.mappings.TeapotMapping;
import io.hosuaby.restful.mappings.TeapotState;
import java.util.Collection;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
|
package io.hosuaby.restful.mappers;
/**
* Mapper between {@link Teapot} and {@link TeapotMapping}.
*/
@Mapper(imports = TeapotState.class)
public abstract class TeapotMapper {
/**
* Creates mapping from teapot.
*
* @param teapot teapot
*
* @return teapot mapping
*/
@Mapping(
target = "state",
expression = "java("
+ "teapot.getIp() != null ? TeapotState.IDLE"
+ " : TeapotState.UNAVAILABLE"
+ ")")
|
// Path: src/main/java/io/hosuaby/restful/domain/Teapot.java
// @Document(collection = "teapots")
// public class Teapot {
//
// /** 0.3 L */
// public static final float L0_3 = (float) 0.3;
//
// /** 0.5 L */
// public static final float L0_5 = (float) 0.5;
//
// /** 1 L */
// public static final float L1 = (float) 1.0;
//
// /** 1.5 L */
// public static final float L1_5 = (float) 1.5;
//
// /** 3 L */
// public static final float L3 = (float) 3.0;
//
// /** 5 L */
// public static final float L5 = (float) 5.0;
//
// /** 8 L */
// public static final float L8 = (float) 8.0;
//
// /** 10 L */
// public static final float L10 = (float) 10.0;
//
// /** Id: valid id */
// private String id;
//
// /** Name: any String */
// private String name;
//
// /** Brand: any String */
// private String brand;
//
// /** Volume: from defined values */
// private float volume;
//
// /** Current IP address. Must be hidden from the web user */
// private Inet4Address ip;
//
// public Teapot() {
// super();
// }
//
// public Teapot(String id, String name, String brand, float volume) {
// super();
// this.id = id;
// this.name = name;
// this.brand = brand;
// this.volume = volume;
// }
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getBrand() {
// return brand;
// }
//
// public void setBrand(String brand) {
// this.brand = brand;
// }
//
// public float getVolume() {
// return volume;
// }
//
// public void setVolume(float volume) {
// this.volume = volume;
// }
//
// public Inet4Address getIp() {
// return ip;
// }
//
// public void setIp(Inet4Address ip) {
// this.ip = ip;
// }
//
// }
//
// Path: src/main/java/io/hosuaby/restful/mappings/TeapotMapping.java
// public class TeapotMapping {
//
// /** Id: valid id */
// private String id;
//
// /** Name: any String */
// private String name;
//
// /** Brand: any String */
// private String brand;
//
// /** Volume: from defined values */
// private float volume;
//
// /** Current state of the teapot */
// private TeapotState state;
//
// public String getId() {
// return id;
// }
//
// public void setId(String id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getBrand() {
// return brand;
// }
//
// public void setBrand(String brand) {
// this.brand = brand;
// }
//
// public float getVolume() {
// return volume;
// }
//
// public void setVolume(float volume) {
// this.volume = volume;
// }
//
// public TeapotState getState() {
// return state;
// }
//
// public void setState(TeapotState state) {
// this.state = state;
// }
//
// }
//
// Path: src/main/java/io/hosuaby/restful/mappings/TeapotState.java
// public enum TeapotState {
//
// /** Teapot connected to the server and waiting for commands */
// IDLE,
//
// /** Teapot is not connected to the server */
// UNAVAILABLE
//
// }
// Path: src/main/java/io/hosuaby/restful/mappers/TeapotMapper.java
import io.hosuaby.restful.domain.Teapot;
import io.hosuaby.restful.mappings.TeapotMapping;
import io.hosuaby.restful.mappings.TeapotState;
import java.util.Collection;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
package io.hosuaby.restful.mappers;
/**
* Mapper between {@link Teapot} and {@link TeapotMapping}.
*/
@Mapper(imports = TeapotState.class)
public abstract class TeapotMapper {
/**
* Creates mapping from teapot.
*
* @param teapot teapot
*
* @return teapot mapping
*/
@Mapping(
target = "state",
expression = "java("
+ "teapot.getIp() != null ? TeapotState.IDLE"
+ " : TeapotState.UNAVAILABLE"
+ ")")
|
public abstract TeapotMapping toMapping(Teapot teapot);
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.