diff --git a/app/build.gradle b/app/build.gradle index ea8d5991..8182adbc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "com.stardust.scriptdroid" minSdkVersion 17 targetSdkVersion 23 - versionCode 200 - versionName "3.0.0 Alpha1" + versionCode 201 + versionName "3.0.0 Alpha2" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" multiDexEnabled true ndk { @@ -132,6 +132,8 @@ dependencies { compile 'com.squareup.retrofit2:converter-gson:2.3.0' compile 'com.squareup.retrofit2:converter-gson:2.3.0' compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0' + //Picasso + compile 'com.squareup.picasso:picasso:2.5.2' // Tasker Plugin compile 'com.twofortyfouram:android-plugin-client-sdk-for-locale:[4.0.2, 5.0[' compile 'com.flurry.android:analytics:7.0.0@aar' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f4f91ba5..6f9c3207 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -82,6 +82,7 @@ + diff --git a/app/src/main/java/com/stardust/scriptdroid/network/NodeBB.java b/app/src/main/java/com/stardust/scriptdroid/network/NodeBB.java new file mode 100644 index 00000000..254e6078 --- /dev/null +++ b/app/src/main/java/com/stardust/scriptdroid/network/NodeBB.java @@ -0,0 +1,41 @@ +package com.stardust.scriptdroid.network; + +import com.google.gson.GsonBuilder; +import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; +import com.stardust.scriptdroid.network.util.WebkitCookieManagerProxy; + +import okhttp3.OkHttpClient; +import retrofit2.Retrofit; +import retrofit2.converter.gson.GsonConverterFactory; + +/** + * Created by Stardust on 2017/9/20. + */ + +public class NodeBB { + + private static final NodeBB sInstance = new NodeBB(); + + private Retrofit mRetrofit; + + NodeBB() { + mRetrofit = new Retrofit.Builder() + .baseUrl("http://www.autojs.org/") + .addConverterFactory(GsonConverterFactory.create(new GsonBuilder() + .setLenient() + .create())) + .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) + .client(new OkHttpClient.Builder() + .cookieJar(new WebkitCookieManagerProxy()) + .build()) + .build(); + } + + public static NodeBB getInstance() { + return sInstance; + } + + public Retrofit getRetrofit() { + return mRetrofit; + } +} diff --git a/app/src/main/java/com/stardust/scriptdroid/network/UserService.java b/app/src/main/java/com/stardust/scriptdroid/network/UserService.java new file mode 100644 index 00000000..d499f7f3 --- /dev/null +++ b/app/src/main/java/com/stardust/scriptdroid/network/UserService.java @@ -0,0 +1,47 @@ +package com.stardust.scriptdroid.network; + +import com.google.gson.GsonBuilder; +import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; +import com.stardust.scriptdroid.network.api.UserApi; +import com.stardust.scriptdroid.network.entity.TokenResponse; +import com.stardust.scriptdroid.network.entity.VerifyResponse; + +import io.reactivex.Observable; +import io.reactivex.ObservableSource; +import io.reactivex.annotations.NonNull; +import io.reactivex.functions.Consumer; +import io.reactivex.functions.Function; +import io.reactivex.schedulers.Schedulers; +import retrofit2.Retrofit; +import retrofit2.converter.gson.GsonConverterFactory; + +/** + * Created by Stardust on 2017/9/20. + */ + +public class UserService { + + private static final UserService sInstance = new UserService(); + private final Retrofit mRetrofit; + + UserService() { + mRetrofit = NodeBB.getInstance().getRetrofit(); + } + + + public Observable login(String userName, final String password) { + final UserApi userApi = mRetrofit.create(UserApi.class); + return userApi.verify(userName, password) + .subscribeOn(Schedulers.io()) + .flatMap(new Function>() { + @Override + public ObservableSource apply(@NonNull VerifyResponse verifyResponse) throws Exception { + if (verifyResponse.isSuccessful()) { + return userApi.generateToken(verifyResponse.getUid(), password); + } else { + return Observable.error(new Exception(verifyResponse.getMessage())); + } + } + }); + } +} diff --git a/app/src/main/java/com/stardust/scriptdroid/network/api/UserApi.java b/app/src/main/java/com/stardust/scriptdroid/network/api/UserApi.java new file mode 100644 index 00000000..b7f64159 --- /dev/null +++ b/app/src/main/java/com/stardust/scriptdroid/network/api/UserApi.java @@ -0,0 +1,34 @@ +package com.stardust.scriptdroid.network.api; + +import com.stardust.scriptdroid.network.entity.VerifyResponse; +import com.stardust.scriptdroid.network.entity.TokenResponse; +import com.stardust.scriptdroid.network.entity.User; + +import io.reactivex.Observable; +import retrofit2.http.Field; +import retrofit2.http.FormUrlEncoded; +import retrofit2.http.GET; +import retrofit2.http.POST; +import retrofit2.http.Path; + +/** + * Created by Stardust on 2017/9/20. + */ + +public interface UserApi { + + @GET("/api/me") + Observable me(); + + @FormUrlEncoded + @POST("/api/ns/login") + Observable verify(@Field("username") String userName, @Field("password") String password); + + + @FormUrlEncoded + @POST("/api/v2/{uid}/tokens") + Observable generateToken(@Path("uid") String uid, @Field("password") String password); + + + +} diff --git a/app/src/main/java/com/stardust/scriptdroid/network/entity/GroupsItem.java b/app/src/main/java/com/stardust/scriptdroid/network/entity/GroupsItem.java new file mode 100644 index 00000000..2c7f5a42 --- /dev/null +++ b/app/src/main/java/com/stardust/scriptdroid/network/entity/GroupsItem.java @@ -0,0 +1,253 @@ +package com.stardust.scriptdroid.network.entity; + +import com.google.gson.annotations.SerializedName; + +public class GroupsItem{ + + @SerializedName("createtimeISO") + private String createtimeISO; + + @SerializedName("createtime") + private String createtime; + + @SerializedName("private") + private boolean jsonMemberPrivate; + + @SerializedName("hidden") + private boolean hidden; + + @SerializedName("userTitleEnabled") + private boolean userTitleEnabled; + + @SerializedName("displayName") + private String displayName; + + @SerializedName("memberCount") + private String memberCount; + + @SerializedName("icon") + private String icon; + + @SerializedName("description") + private String description; + + @SerializedName("labelColor") + private String labelColor; + + @SerializedName("userTitle") + private String userTitle; + + @SerializedName("deleted") + private String deleted; + + @SerializedName("system") + private boolean system; + + @SerializedName("cover:position") + private String coverPosition; + + @SerializedName("name") + private String name; + + @SerializedName("cover:url") + private String coverUrl; + + @SerializedName("cover:thumb:url") + private String coverThumbUrl; + + @SerializedName("disableJoinRequests") + private boolean disableJoinRequests; + + @SerializedName("slug") + private String slug; + + @SerializedName("nameEncoded") + private String nameEncoded; + + public void setCreatetimeISO(String createtimeISO){ + this.createtimeISO = createtimeISO; + } + + public String getCreatetimeISO(){ + return createtimeISO; + } + + public void setCreatetime(String createtime){ + this.createtime = createtime; + } + + public String getCreatetime(){ + return createtime; + } + + public void setJsonMemberPrivate(boolean jsonMemberPrivate){ + this.jsonMemberPrivate = jsonMemberPrivate; + } + + public boolean isJsonMemberPrivate(){ + return jsonMemberPrivate; + } + + public void setHidden(boolean hidden){ + this.hidden = hidden; + } + + public boolean isHidden(){ + return hidden; + } + + public void setUserTitleEnabled(boolean userTitleEnabled){ + this.userTitleEnabled = userTitleEnabled; + } + + public boolean isUserTitleEnabled(){ + return userTitleEnabled; + } + + public void setDisplayName(String displayName){ + this.displayName = displayName; + } + + public String getDisplayName(){ + return displayName; + } + + public void setMemberCount(String memberCount){ + this.memberCount = memberCount; + } + + public String getMemberCount(){ + return memberCount; + } + + public void setIcon(String icon){ + this.icon = icon; + } + + public String getIcon(){ + return icon; + } + + public void setDescription(String description){ + this.description = description; + } + + public String getDescription(){ + return description; + } + + public void setLabelColor(String labelColor){ + this.labelColor = labelColor; + } + + public String getLabelColor(){ + return labelColor; + } + + public void setUserTitle(String userTitle){ + this.userTitle = userTitle; + } + + public String getUserTitle(){ + return userTitle; + } + + public void setDeleted(String deleted){ + this.deleted = deleted; + } + + public String getDeleted(){ + return deleted; + } + + public void setSystem(boolean system){ + this.system = system; + } + + public boolean isSystem(){ + return system; + } + + public void setCoverPosition(String coverPosition){ + this.coverPosition = coverPosition; + } + + public String getCoverPosition(){ + return coverPosition; + } + + public void setName(String name){ + this.name = name; + } + + public String getName(){ + return name; + } + + public void setCoverUrl(String coverUrl){ + this.coverUrl = coverUrl; + } + + public String getCoverUrl(){ + return coverUrl; + } + + public void setCoverThumbUrl(String coverThumbUrl){ + this.coverThumbUrl = coverThumbUrl; + } + + public String getCoverThumbUrl(){ + return coverThumbUrl; + } + + public void setDisableJoinRequests(boolean disableJoinRequests){ + this.disableJoinRequests = disableJoinRequests; + } + + public boolean isDisableJoinRequests(){ + return disableJoinRequests; + } + + public void setSlug(String slug){ + this.slug = slug; + } + + public String getSlug(){ + return slug; + } + + public void setNameEncoded(String nameEncoded){ + this.nameEncoded = nameEncoded; + } + + public String getNameEncoded(){ + return nameEncoded; + } + + @Override + public String toString(){ + return + "GroupsItem{" + + "createtimeISO = '" + createtimeISO + '\'' + + ",createtime = '" + createtime + '\'' + + ",private = '" + jsonMemberPrivate + '\'' + + ",hidden = '" + hidden + '\'' + + ",userTitleEnabled = '" + userTitleEnabled + '\'' + + ",displayName = '" + displayName + '\'' + + ",memberCount = '" + memberCount + '\'' + + ",icon = '" + icon + '\'' + + ",description = '" + description + '\'' + + ",labelColor = '" + labelColor + '\'' + + ",userTitle = '" + userTitle + '\'' + + ",deleted = '" + deleted + '\'' + + ",system = '" + system + '\'' + + ",cover:position = '" + coverPosition + '\'' + + ",name = '" + name + '\'' + + ",cover:url = '" + coverUrl + '\'' + + ",cover:thumb:url = '" + coverThumbUrl + '\'' + + ",disableJoinRequests = '" + disableJoinRequests + '\'' + + ",slug = '" + slug + '\'' + + ",nameEncoded = '" + nameEncoded + '\'' + + "}"; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/stardust/scriptdroid/network/entity/TokenResponse.java b/app/src/main/java/com/stardust/scriptdroid/network/entity/TokenResponse.java new file mode 100644 index 00000000..e87ad11e --- /dev/null +++ b/app/src/main/java/com/stardust/scriptdroid/network/entity/TokenResponse.java @@ -0,0 +1,17 @@ +package com.stardust.scriptdroid.network.entity; + +/** + * Created by Stardust on 2017/9/21. + */ + +public class TokenResponse { + + public String code; + + public static class Payload { + + public String token; + } + + +} diff --git a/app/src/main/java/com/stardust/scriptdroid/network/entity/User.java b/app/src/main/java/com/stardust/scriptdroid/network/entity/User.java new file mode 100644 index 00000000..5c97da2c --- /dev/null +++ b/app/src/main/java/com/stardust/scriptdroid/network/entity/User.java @@ -0,0 +1,746 @@ +package com.stardust.scriptdroid.network.entity; + +import java.util.List; +import com.google.gson.annotations.SerializedName; + +public class User{ + + @SerializedName("websiteLink") + private String websiteLink; + + @SerializedName("reputation") + private String reputation; + + @SerializedName("sso") + private List sso; + + @SerializedName("icon:text") + private String iconText; + + @SerializedName("isGlobalModerator") + private boolean isGlobalModerator; + + @SerializedName("joindate") + private String joindate; + + @SerializedName("profile_links") + private List profileLinks; + + @SerializedName("reputation:disabled") + private boolean reputationDisabled; + + @SerializedName("isAdmin") + private boolean isAdmin; + + @SerializedName("moderationNote") + private String moderationNote; + + @SerializedName("ips") + private List ips; + + @SerializedName("aboutme") + private String aboutme; + + @SerializedName("isTargetAdmin") + private boolean isTargetAdmin; + + @SerializedName("email:confirmed") + private boolean emailConfirmed; + + @SerializedName("isAdminOrGlobalModerator") + private boolean isAdminOrGlobalModerator; + + @SerializedName("emailClass") + private String emailClass; + + @SerializedName("downvote:disabled") + private boolean downvoteDisabled; + + @SerializedName("topiccount") + private String topiccount; + + @SerializedName("isSelf") + private boolean isSelf; + + @SerializedName("status") + private String status; + + @SerializedName("birthday") + private String birthday; + + @SerializedName("showHidden") + private boolean showHidden; + + @SerializedName("yourid") + private int yourid; + + @SerializedName("lastposttime") + private String lastposttime; + + @SerializedName("isModerator") + private boolean isModerator; + + @SerializedName("signature") + private String signature; + + @SerializedName("icon:bgColor") + private String iconBgColor; + + @SerializedName("canEdit") + private boolean canEdit; + + @SerializedName("groupTitle") + private String groupTitle; + + @SerializedName("followingCount") + private int followingCount; + + @SerializedName("lastonlineISO") + private String lastonlineISO; + + @SerializedName("email:disableEdit") + private boolean emailDisableEdit; + + @SerializedName("uid") + private String uid; + + @SerializedName("canChangePassword") + private boolean canChangePassword; + + @SerializedName("profileviews") + private String profileviews; + + @SerializedName("cover:url") + private String coverUrl; + + @SerializedName("banned") + private boolean banned; + + @SerializedName("userslug") + private String userslug; + + @SerializedName("followerCount") + private int followerCount; + + @SerializedName("email") + private String email; + + @SerializedName("website") + private String website; + + @SerializedName("isFollowing") + private boolean isFollowing; + + @SerializedName("uploadedpicture") + private String uploadedpicture; + + @SerializedName("passwordExpiry") + private String passwordExpiry; + + @SerializedName("canBan") + private boolean canBan; + + @SerializedName("lastonline") + private String lastonline; + + @SerializedName("disableSignatures") + private boolean disableSignatures; + + @SerializedName("groups") + private List groups; + + @SerializedName("username:disableEdit") + private boolean usernameDisableEdit; + + @SerializedName("picture") + private String picture; + + @SerializedName("joindateISO") + private String joindateISO; + + @SerializedName("isSelfOrAdminOrGlobalModerator") + private boolean isSelfOrAdminOrGlobalModerator; + + @SerializedName("websiteName") + private String websiteName; + + @SerializedName("isAdminOrGlobalModeratorOrModerator") + private boolean isAdminOrGlobalModeratorOrModerator; + + @SerializedName("cover:position") + private String coverPosition; + + @SerializedName("postcount") + private String postcount; + + @SerializedName("location") + private String location; + + @SerializedName("fullname") + private String fullname; + + @SerializedName("age") + private int age; + + @SerializedName("theirid") + private String theirid; + + @SerializedName("username") + private String username; + + public void setWebsiteLink(String websiteLink){ + this.websiteLink = websiteLink; + } + + public String getWebsiteLink(){ + return websiteLink; + } + + public void setReputation(String reputation){ + this.reputation = reputation; + } + + public String getReputation(){ + return reputation; + } + + public void setSso(List sso){ + this.sso = sso; + } + + public List getSso(){ + return sso; + } + + public void setIconText(String iconText){ + this.iconText = iconText; + } + + public String getIconText(){ + return iconText; + } + + public void setIsGlobalModerator(boolean isGlobalModerator){ + this.isGlobalModerator = isGlobalModerator; + } + + public boolean isIsGlobalModerator(){ + return isGlobalModerator; + } + + public void setJoindate(String joindate){ + this.joindate = joindate; + } + + public String getJoindate(){ + return joindate; + } + + public void setProfileLinks(List profileLinks){ + this.profileLinks = profileLinks; + } + + public List getProfileLinks(){ + return profileLinks; + } + + public void setReputationDisabled(boolean reputationDisabled){ + this.reputationDisabled = reputationDisabled; + } + + public boolean isReputationDisabled(){ + return reputationDisabled; + } + + public void setIsAdmin(boolean isAdmin){ + this.isAdmin = isAdmin; + } + + public boolean isIsAdmin(){ + return isAdmin; + } + + public void setModerationNote(String moderationNote){ + this.moderationNote = moderationNote; + } + + public String getModerationNote(){ + return moderationNote; + } + + public void setIps(List ips){ + this.ips = ips; + } + + public List getIps(){ + return ips; + } + + public void setAboutme(String aboutme){ + this.aboutme = aboutme; + } + + public String getAboutme(){ + return aboutme; + } + + public void setIsTargetAdmin(boolean isTargetAdmin){ + this.isTargetAdmin = isTargetAdmin; + } + + public boolean isIsTargetAdmin(){ + return isTargetAdmin; + } + + public void setEmailConfirmed(boolean emailConfirmed){ + this.emailConfirmed = emailConfirmed; + } + + public boolean isEmailConfirmed(){ + return emailConfirmed; + } + + public void setIsAdminOrGlobalModerator(boolean isAdminOrGlobalModerator){ + this.isAdminOrGlobalModerator = isAdminOrGlobalModerator; + } + + public boolean isIsAdminOrGlobalModerator(){ + return isAdminOrGlobalModerator; + } + + public void setEmailClass(String emailClass){ + this.emailClass = emailClass; + } + + public String getEmailClass(){ + return emailClass; + } + + public void setDownvoteDisabled(boolean downvoteDisabled){ + this.downvoteDisabled = downvoteDisabled; + } + + public boolean isDownvoteDisabled(){ + return downvoteDisabled; + } + + public void setTopiccount(String topiccount){ + this.topiccount = topiccount; + } + + public String getTopiccount(){ + return topiccount; + } + + public void setIsSelf(boolean isSelf){ + this.isSelf = isSelf; + } + + public boolean isIsSelf(){ + return isSelf; + } + + public void setStatus(String status){ + this.status = status; + } + + public String getStatus(){ + return status; + } + + public void setBirthday(String birthday){ + this.birthday = birthday; + } + + public String getBirthday(){ + return birthday; + } + + public void setShowHidden(boolean showHidden){ + this.showHidden = showHidden; + } + + public boolean isShowHidden(){ + return showHidden; + } + + public void setYourid(int yourid){ + this.yourid = yourid; + } + + public int getYourid(){ + return yourid; + } + + public void setLastposttime(String lastposttime){ + this.lastposttime = lastposttime; + } + + public String getLastposttime(){ + return lastposttime; + } + + public void setIsModerator(boolean isModerator){ + this.isModerator = isModerator; + } + + public boolean isIsModerator(){ + return isModerator; + } + + public void setSignature(String signature){ + this.signature = signature; + } + + public String getSignature(){ + return signature; + } + + public void setIconBgColor(String iconBgColor){ + this.iconBgColor = iconBgColor; + } + + public String getIconBgColor(){ + return iconBgColor; + } + + public void setCanEdit(boolean canEdit){ + this.canEdit = canEdit; + } + + public boolean isCanEdit(){ + return canEdit; + } + + public void setGroupTitle(String groupTitle){ + this.groupTitle = groupTitle; + } + + public String getGroupTitle(){ + return groupTitle; + } + + public void setFollowingCount(int followingCount){ + this.followingCount = followingCount; + } + + public int getFollowingCount(){ + return followingCount; + } + + public void setLastonlineISO(String lastonlineISO){ + this.lastonlineISO = lastonlineISO; + } + + public String getLastonlineISO(){ + return lastonlineISO; + } + + public void setEmailDisableEdit(boolean emailDisableEdit){ + this.emailDisableEdit = emailDisableEdit; + } + + public boolean isEmailDisableEdit(){ + return emailDisableEdit; + } + + public void setUid(String uid){ + this.uid = uid; + } + + public String getUid(){ + return uid; + } + + public void setCanChangePassword(boolean canChangePassword){ + this.canChangePassword = canChangePassword; + } + + public boolean isCanChangePassword(){ + return canChangePassword; + } + + public void setProfileviews(String profileviews){ + this.profileviews = profileviews; + } + + public String getProfileviews(){ + return profileviews; + } + + public void setCoverUrl(String coverUrl){ + this.coverUrl = coverUrl; + } + + public String getCoverUrl(){ + return coverUrl; + } + + public void setBanned(boolean banned){ + this.banned = banned; + } + + public boolean isBanned(){ + return banned; + } + + public void setUserslug(String userslug){ + this.userslug = userslug; + } + + public String getUserslug(){ + return userslug; + } + + public void setFollowerCount(int followerCount){ + this.followerCount = followerCount; + } + + public int getFollowerCount(){ + return followerCount; + } + + public void setEmail(String email){ + this.email = email; + } + + public String getEmail(){ + return email; + } + + public void setWebsite(String website){ + this.website = website; + } + + public String getWebsite(){ + return website; + } + + public void setIsFollowing(boolean isFollowing){ + this.isFollowing = isFollowing; + } + + public boolean isIsFollowing(){ + return isFollowing; + } + + public void setUploadedpicture(String uploadedpicture){ + this.uploadedpicture = uploadedpicture; + } + + public String getUploadedpicture(){ + return uploadedpicture; + } + + public void setPasswordExpiry(String passwordExpiry){ + this.passwordExpiry = passwordExpiry; + } + + public String getPasswordExpiry(){ + return passwordExpiry; + } + + public void setCanBan(boolean canBan){ + this.canBan = canBan; + } + + public boolean isCanBan(){ + return canBan; + } + + public void setLastonline(String lastonline){ + this.lastonline = lastonline; + } + + public String getLastonline(){ + return lastonline; + } + + public void setDisableSignatures(boolean disableSignatures){ + this.disableSignatures = disableSignatures; + } + + public boolean isDisableSignatures(){ + return disableSignatures; + } + + public void setGroups(List groups){ + this.groups = groups; + } + + public List getGroups(){ + return groups; + } + + public void setUsernameDisableEdit(boolean usernameDisableEdit){ + this.usernameDisableEdit = usernameDisableEdit; + } + + public boolean isUsernameDisableEdit(){ + return usernameDisableEdit; + } + + public void setPicture(String picture){ + this.picture = picture; + } + + public String getPicture(){ + return picture; + } + + public void setJoindateISO(String joindateISO){ + this.joindateISO = joindateISO; + } + + public String getJoindateISO(){ + return joindateISO; + } + + public void setIsSelfOrAdminOrGlobalModerator(boolean isSelfOrAdminOrGlobalModerator){ + this.isSelfOrAdminOrGlobalModerator = isSelfOrAdminOrGlobalModerator; + } + + public boolean isIsSelfOrAdminOrGlobalModerator(){ + return isSelfOrAdminOrGlobalModerator; + } + + public void setWebsiteName(String websiteName){ + this.websiteName = websiteName; + } + + public String getWebsiteName(){ + return websiteName; + } + + public void setIsAdminOrGlobalModeratorOrModerator(boolean isAdminOrGlobalModeratorOrModerator){ + this.isAdminOrGlobalModeratorOrModerator = isAdminOrGlobalModeratorOrModerator; + } + + public boolean isIsAdminOrGlobalModeratorOrModerator(){ + return isAdminOrGlobalModeratorOrModerator; + } + + public void setCoverPosition(String coverPosition){ + this.coverPosition = coverPosition; + } + + public String getCoverPosition(){ + return coverPosition; + } + + public void setPostcount(String postcount){ + this.postcount = postcount; + } + + public String getPostcount(){ + return postcount; + } + + public void setLocation(String location){ + this.location = location; + } + + public String getLocation(){ + return location; + } + + public void setFullname(String fullname){ + this.fullname = fullname; + } + + public String getFullname(){ + return fullname; + } + + public void setAge(int age){ + this.age = age; + } + + public int getAge(){ + return age; + } + + public void setTheirid(String theirid){ + this.theirid = theirid; + } + + public String getTheirid(){ + return theirid; + } + + public void setUsername(String username){ + this.username = username; + } + + public String getUsername(){ + return username; + } + + @Override + public String toString(){ + return + "User{" + + "websiteLink = '" + websiteLink + '\'' + + ",reputation = '" + reputation + '\'' + + ",sso = '" + sso + '\'' + + ",icon:text = '" + iconText + '\'' + + ",isGlobalModerator = '" + isGlobalModerator + '\'' + + ",joindate = '" + joindate + '\'' + + ",profile_links = '" + profileLinks + '\'' + + ",reputation:disabled = '" + reputationDisabled + '\'' + + ",isAdmin = '" + isAdmin + '\'' + + ",moderationNote = '" + moderationNote + '\'' + + ",ips = '" + ips + '\'' + + ",aboutme = '" + aboutme + '\'' + + ",isTargetAdmin = '" + isTargetAdmin + '\'' + + ",email:confirmed = '" + emailConfirmed + '\'' + + ",isAdminOrGlobalModerator = '" + isAdminOrGlobalModerator + '\'' + + ",emailClass = '" + emailClass + '\'' + + ",downvote:disabled = '" + downvoteDisabled + '\'' + + ",topiccount = '" + topiccount + '\'' + + ",isSelf = '" + isSelf + '\'' + + ",status = '" + status + '\'' + + ",birthday = '" + birthday + '\'' + + ",showHidden = '" + showHidden + '\'' + + ",yourid = '" + yourid + '\'' + + ",lastposttime = '" + lastposttime + '\'' + + ",isModerator = '" + isModerator + '\'' + + ",signature = '" + signature + '\'' + + ",icon:bgColor = '" + iconBgColor + '\'' + + ",canEdit = '" + canEdit + '\'' + + ",groupTitle = '" + groupTitle + '\'' + + ",followingCount = '" + followingCount + '\'' + + ",lastonlineISO = '" + lastonlineISO + '\'' + + ",email:disableEdit = '" + emailDisableEdit + '\'' + + ",uid = '" + uid + '\'' + + ",canChangePassword = '" + canChangePassword + '\'' + + ",profileviews = '" + profileviews + '\'' + + ",cover:url = '" + coverUrl + '\'' + + ",banned = '" + banned + '\'' + + ",userslug = '" + userslug + '\'' + + ",followerCount = '" + followerCount + '\'' + + ",email = '" + email + '\'' + + ",website = '" + website + '\'' + + ",isFollowing = '" + isFollowing + '\'' + + ",uploadedpicture = '" + uploadedpicture + '\'' + + ",passwordExpiry = '" + passwordExpiry + '\'' + + ",canBan = '" + canBan + '\'' + + ",lastonline = '" + lastonline + '\'' + + ",disableSignatures = '" + disableSignatures + '\'' + + ",groups = '" + groups + '\'' + + ",username:disableEdit = '" + usernameDisableEdit + '\'' + + ",picture = '" + picture + '\'' + + ",joindateISO = '" + joindateISO + '\'' + + ",isSelfOrAdminOrGlobalModerator = '" + isSelfOrAdminOrGlobalModerator + '\'' + + ",websiteName = '" + websiteName + '\'' + + ",isAdminOrGlobalModeratorOrModerator = '" + isAdminOrGlobalModeratorOrModerator + '\'' + + ",cover:position = '" + coverPosition + '\'' + + ",postcount = '" + postcount + '\'' + + ",location = '" + location + '\'' + + ",fullname = '" + fullname + '\'' + + ",age = '" + age + '\'' + + ",theirid = '" + theirid + '\'' + + ",username = '" + username + '\'' + + "}"; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/stardust/scriptdroid/network/entity/VerifyResponse.java b/app/src/main/java/com/stardust/scriptdroid/network/entity/VerifyResponse.java new file mode 100644 index 00000000..56cefbff --- /dev/null +++ b/app/src/main/java/com/stardust/scriptdroid/network/entity/VerifyResponse.java @@ -0,0 +1,376 @@ +package com.stardust.scriptdroid.network.entity; + +import com.google.gson.annotations.SerializedName; + +public class VerifyResponse { + + @SerializedName("message") + private String message; + + @SerializedName("birthday") + private String birthday; + + @SerializedName("lastposttime") + private String lastposttime; + + @SerializedName("signature") + private String signature; + + @SerializedName("icon:bgColor") + private String iconBgColor; + + @SerializedName("groupTitle") + private String groupTitle; + + @SerializedName("reputation") + private String reputation; + + @SerializedName("followingCount") + private String followingCount; + + @SerializedName("lastonlineISO") + private String lastonlineISO; + + @SerializedName("uid") + private String uid; + + @SerializedName("profileviews") + private String profileviews; + + @SerializedName("icon:text") + private String iconText; + + @SerializedName("banned") + private String banned; + + @SerializedName("userslug") + private String userslug; + + @SerializedName("followerCount") + private String followerCount; + + @SerializedName("email") + private String email; + + @SerializedName("joindate") + private String joindate; + + @SerializedName("website") + private String website; + + @SerializedName("uploadedpicture") + private String uploadedpicture; + + @SerializedName("passwordExpiry") + private String passwordExpiry; + + @SerializedName("lastonline") + private String lastonline; + + @SerializedName("picture") + private String picture; + + @SerializedName("joindateISO") + private String joindateISO; + + @SerializedName("email:confirmed") + private Object emailConfirmed; + + @SerializedName("postcount") + private String postcount; + + @SerializedName("location") + private String location; + + @SerializedName("fullname") + private String fullname; + + @SerializedName("topiccount") + private String topiccount; + + @SerializedName("username") + private String username; + + @SerializedName("status") + private String status; + + public boolean isSuccessful() { + return message == null; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public void setBirthday(String birthday) { + this.birthday = birthday; + } + + public String getBirthday() { + return birthday; + } + + public void setLastposttime(String lastposttime) { + this.lastposttime = lastposttime; + } + + public String getLastposttime() { + return lastposttime; + } + + public void setSignature(String signature) { + this.signature = signature; + } + + public String getSignature() { + return signature; + } + + public void setIconBgColor(String iconBgColor) { + this.iconBgColor = iconBgColor; + } + + public String getIconBgColor() { + return iconBgColor; + } + + public void setGroupTitle(String groupTitle) { + this.groupTitle = groupTitle; + } + + public String getGroupTitle() { + return groupTitle; + } + + public void setReputation(String reputation) { + this.reputation = reputation; + } + + public String getReputation() { + return reputation; + } + + public void setFollowingCount(String followingCount) { + this.followingCount = followingCount; + } + + public String getFollowingCount() { + return followingCount; + } + + public void setLastonlineISO(String lastonlineISO) { + this.lastonlineISO = lastonlineISO; + } + + public String getLastonlineISO() { + return lastonlineISO; + } + + public void setUid(String uid) { + this.uid = uid; + } + + public String getUid() { + return uid; + } + + public void setProfileviews(String profileviews) { + this.profileviews = profileviews; + } + + public String getProfileviews() { + return profileviews; + } + + public void setIconText(String iconText) { + this.iconText = iconText; + } + + public String getIconText() { + return iconText; + } + + public void setBanned(String banned) { + this.banned = banned; + } + + public String getBanned() { + return banned; + } + + public void setUserslug(String userslug) { + this.userslug = userslug; + } + + public String getUserslug() { + return userslug; + } + + public void setFollowerCount(String followerCount) { + this.followerCount = followerCount; + } + + public String getFollowerCount() { + return followerCount; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getEmail() { + return email; + } + + public void setJoindate(String joindate) { + this.joindate = joindate; + } + + public String getJoindate() { + return joindate; + } + + public void setWebsite(String website) { + this.website = website; + } + + public String getWebsite() { + return website; + } + + public void setUploadedpicture(String uploadedpicture) { + this.uploadedpicture = uploadedpicture; + } + + public String getUploadedpicture() { + return uploadedpicture; + } + + public void setPasswordExpiry(String passwordExpiry) { + this.passwordExpiry = passwordExpiry; + } + + public String getPasswordExpiry() { + return passwordExpiry; + } + + public void setLastonline(String lastonline) { + this.lastonline = lastonline; + } + + public String getLastonline() { + return lastonline; + } + + public void setPicture(String picture) { + this.picture = picture; + } + + public String getPicture() { + return picture; + } + + public void setJoindateISO(String joindateISO) { + this.joindateISO = joindateISO; + } + + public String getJoindateISO() { + return joindateISO; + } + + public void setEmailConfirmed(Object emailConfirmed) { + this.emailConfirmed = emailConfirmed; + } + + public Object getEmailConfirmed() { + return emailConfirmed; + } + + public void setPostcount(String postcount) { + this.postcount = postcount; + } + + public String getPostcount() { + return postcount; + } + + public void setLocation(String location) { + this.location = location; + } + + public String getLocation() { + return location; + } + + public void setFullname(String fullname) { + this.fullname = fullname; + } + + public String getFullname() { + return fullname; + } + + public void setTopiccount(String topiccount) { + this.topiccount = topiccount; + } + + public String getTopiccount() { + return topiccount; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getUsername() { + return username; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatus() { + return status; + } + + @Override + public String toString() { + return + "VerifyResponse{" + + "birthday = '" + birthday + '\'' + + ",lastposttime = '" + lastposttime + '\'' + + ",signature = '" + signature + '\'' + + ",icon:bgColor = '" + iconBgColor + '\'' + + ",groupTitle = '" + groupTitle + '\'' + + ",reputation = '" + reputation + '\'' + + ",followingCount = '" + followingCount + '\'' + + ",lastonlineISO = '" + lastonlineISO + '\'' + + ",uid = '" + uid + '\'' + + ",profileviews = '" + profileviews + '\'' + + ",icon:text = '" + iconText + '\'' + + ",banned = '" + banned + '\'' + + ",userslug = '" + userslug + '\'' + + ",followerCount = '" + followerCount + '\'' + + ",email = '" + email + '\'' + + ",joindate = '" + joindate + '\'' + + ",website = '" + website + '\'' + + ",uploadedpicture = '" + uploadedpicture + '\'' + + ",passwordExpiry = '" + passwordExpiry + '\'' + + ",lastonline = '" + lastonline + '\'' + + ",picture = '" + picture + '\'' + + ",joindateISO = '" + joindateISO + '\'' + + ",email:confirmed = '" + emailConfirmed + '\'' + + ",postcount = '" + postcount + '\'' + + ",location = '" + location + '\'' + + ",fullname = '" + fullname + '\'' + + ",topiccount = '" + topiccount + '\'' + + ",username = '" + username + '\'' + + ",status = '" + status + '\'' + + "}"; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/stardust/scriptdroid/network/util/WebkitCookieManagerProxy.java b/app/src/main/java/com/stardust/scriptdroid/network/util/WebkitCookieManagerProxy.java new file mode 100644 index 00000000..6a88da16 --- /dev/null +++ b/app/src/main/java/com/stardust/scriptdroid/network/util/WebkitCookieManagerProxy.java @@ -0,0 +1,130 @@ +package com.stardust.scriptdroid.network.util; + +import android.util.Log; + +import java.io.IOException; +import java.net.CookieManager; +import java.net.CookiePolicy; +import java.net.CookieStore; +import java.net.URI; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import okhttp3.Cookie; +import okhttp3.CookieJar; +import okhttp3.HttpUrl; + +/** + * Created by Stardust on 2017/9/20. + */ + +public class WebkitCookieManagerProxy extends CookieManager implements CookieJar { + private android.webkit.CookieManager webkitCookieManager; + + private static final String TAG = WebkitCookieManagerProxy.class.getSimpleName(); + + public WebkitCookieManagerProxy() { + this(null, null); + } + + WebkitCookieManagerProxy(CookieStore store, CookiePolicy cookiePolicy) { + super(null, cookiePolicy); + this.webkitCookieManager = android.webkit.CookieManager.getInstance(); + } + + @Override + public void put(URI uri, Map> responseHeaders) + throws IOException { + // make sure our args are valid + if ((uri == null) || (responseHeaders == null)) + return; + + // save our url once + String url = uri.toString(); + + // go over the headers + for (String headerKey : responseHeaders.keySet()) { + // ignore headers which aren't cookie related + if ((headerKey == null) + || !(headerKey.equalsIgnoreCase("Set-Cookie2") || headerKey + .equalsIgnoreCase("Set-Cookie"))) + continue; + + // process each of the headers + for (String headerValue : responseHeaders.get(headerKey)) { + webkitCookieManager.setCookie(url, headerValue); + } + } + } + + @Override + public Map> get(URI uri, + Map> requestHeaders) throws IOException { + // make sure our args are valid + if ((uri == null) || (requestHeaders == null)) + throw new IllegalArgumentException("Argument is null"); + + // save our url once + String url = uri.toString(); + + // prepare our response + Map> res = new java.util.HashMap>(); + + // get the cookie + String cookie = webkitCookieManager.getCookie(url); + + // return it + if (cookie != null) { + res.put("Cookie", Arrays.asList(cookie)); + } + + return res; + } + + @Override + public CookieStore getCookieStore() { + // we don't want anyone to work with this cookie store directly + throw new UnsupportedOperationException(); + } + + @Override + public void saveFromResponse(HttpUrl url, List cookies) { + HashMap> generatedResponseHeaders = new HashMap<>(); + ArrayList cookiesList = new ArrayList<>(); + for (Cookie c : cookies) { + // toString correctly generates a normal cookie string + cookiesList.add(c.toString()); + } + + generatedResponseHeaders.put("Set-Cookie", cookiesList); + try { + put(url.uri(), generatedResponseHeaders); + } catch (IOException e) { + Log.e(TAG, "Error adding cookies through okhttp", e); + } + } + + @Override + public List loadForRequest(HttpUrl url) { + ArrayList cookieArrayList = new ArrayList<>(); + try { + Map> cookieList = get(url.uri(), new HashMap>()); + // Format here looks like: "Cookie":["cookie1=val1;cookie2=val2;"] + for (List ls : cookieList.values()) { + for (String s : ls) { + String[] cookies = s.split(";"); + for (String cookie : cookies) { + Cookie c = Cookie.parse(url, cookie); + cookieArrayList.add(c); + } + } + } + } catch (IOException e) { + Log.e(TAG, "error making cookie!", e); + } + return cookieArrayList; + } +} diff --git a/app/src/main/java/com/stardust/scriptdroid/ui/login/LoginActivity.java b/app/src/main/java/com/stardust/scriptdroid/ui/login/LoginActivity.java new file mode 100644 index 00000000..45093339 --- /dev/null +++ b/app/src/main/java/com/stardust/scriptdroid/ui/login/LoginActivity.java @@ -0,0 +1,77 @@ +package com.stardust.scriptdroid.ui.login; + +import android.util.Log; +import android.widget.TextView; + +import com.stardust.scriptdroid.R; +import com.stardust.scriptdroid.network.NodeBB; +import com.stardust.scriptdroid.network.api.UserApi; +import com.stardust.scriptdroid.network.entity.VerifyResponse; +import com.stardust.scriptdroid.tool.SimpleObserver; +import com.stardust.scriptdroid.ui.BaseActivity; + +import org.androidannotations.annotations.AfterViews; +import org.androidannotations.annotations.Click; +import org.androidannotations.annotations.EActivity; +import org.androidannotations.annotations.ViewById; + +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.annotations.NonNull; +import io.reactivex.schedulers.Schedulers; + +/** + * Created by Stardust on 2017/9/20. + */ +@EActivity(R.layout.activity_login) +public class LoginActivity extends BaseActivity { + + @ViewById(R.id.username) + TextView mUserName; + + @ViewById(R.id.password) + TextView mPassword; + + @AfterViews + void setUpViews() { + setToolbarAsBack(getString(R.string.text_login)); + } + + @Click(R.id.login) + void login() { + String userName = mUserName.getText().toString(); + String password = mPassword.getText().toString(); + if (!checkNotEmpty(userName, password)) { + return; + } + + NodeBB.getInstance().getRetrofit() + .create(UserApi.class) + .verify(userName, password) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new SimpleObserver() { + + @Override + public void onNext(@NonNull VerifyResponse verifyResponse) { + Log.d("Login", verifyResponse.toString()); + } + + @Override + public void onError(@NonNull Throwable e) { + e.printStackTrace(); + } + }); + } + + private boolean checkNotEmpty(String userName, String password) { + if (userName.isEmpty()) { + mUserName.setError(getString(R.string.text_username_cannot_be_empty)); + return false; + } + if (password.isEmpty()) { + mUserName.setError(getString(R.string.text_password_cannot_be_empty)); + return false; + } + return true; + } +} diff --git a/app/src/main/java/com/stardust/scriptdroid/ui/main/community/CommunityFragment.java b/app/src/main/java/com/stardust/scriptdroid/ui/main/community/CommunityFragment.java index 305abce2..a782b72d 100644 --- a/app/src/main/java/com/stardust/scriptdroid/ui/main/community/CommunityFragment.java +++ b/app/src/main/java/com/stardust/scriptdroid/ui/main/community/CommunityFragment.java @@ -1,12 +1,7 @@ package com.stardust.scriptdroid.ui.main.community; import android.app.Activity; -import android.content.Context; import android.support.design.widget.FloatingActionButton; -import android.support.v4.app.Fragment; -import android.support.v4.view.ViewPager; -import android.support.v4.view.animation.FastOutSlowInInterpolator; -import android.view.View; import android.webkit.WebView; import com.stardust.scriptdroid.R; @@ -18,6 +13,8 @@ import org.androidannotations.annotations.AfterViews; import org.androidannotations.annotations.EFragment; import org.androidannotations.annotations.ViewById; +import java.util.regex.Pattern; + /** * Created by Stardust on 2017/8/22. */ @@ -25,6 +22,8 @@ import org.androidannotations.annotations.ViewById; public class CommunityFragment extends ViewPagerFragment implements BackPressedHandler { + private static final String POSTS_PAGE_PATTERN = "[\\S\\s]+/topic/[0-9]+/[\\S\\s]+"; + @ViewById(R.id.eweb_view) EWebView mEWebView; WebView mWebView; @@ -67,6 +66,15 @@ public class CommunityFragment extends ViewPagerFragment implements BackPressedH @Override protected void onFabClick(FloatingActionButton fab) { + if (isInPostsPage()) { + mWebView.loadUrl("javascript:$('button[component=\"topic/reply\"]').click()"); + } else { + mWebView.loadUrl("javascript:$('.new_topic').click()"); + } + } + private boolean isInPostsPage() { + String url = mWebView.getUrl(); + return url.matches(POSTS_PAGE_PATTERN); } } diff --git a/app/src/main/java/com/stardust/scriptdroid/ui/main/drawer/DrawerFragment.java b/app/src/main/java/com/stardust/scriptdroid/ui/main/drawer/DrawerFragment.java index 60deb800..e944fc34 100644 --- a/app/src/main/java/com/stardust/scriptdroid/ui/main/drawer/DrawerFragment.java +++ b/app/src/main/java/com/stardust/scriptdroid/ui/main/drawer/DrawerFragment.java @@ -5,6 +5,8 @@ import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; import android.widget.Toast; import com.afollestad.materialdialogs.DialogAction; @@ -14,9 +16,14 @@ import com.stardust.scriptdroid.Pref; import com.stardust.scriptdroid.R; import com.stardust.scriptdroid.external.floatingwindow.HoverMenuManger; import com.stardust.scriptdroid.external.floatingwindow.menu.HoverMenuService; +import com.stardust.scriptdroid.network.NodeBB; import com.stardust.scriptdroid.network.VersionService; +import com.stardust.scriptdroid.network.api.UserApi; +import com.stardust.scriptdroid.network.entity.User; import com.stardust.scriptdroid.network.entity.VersionInfo; import com.stardust.scriptdroid.tool.SimpleObserver; +import com.stardust.scriptdroid.ui.login.LoginActivity; +import com.stardust.scriptdroid.ui.login.LoginActivity_; import com.stardust.scriptdroid.ui.settings.SettingsActivity; import com.stardust.scriptdroid.ui.update.UpdateInfoDialogBuilder; import com.stardust.theme.ThemeColorManager; @@ -64,6 +71,12 @@ public class DrawerFragment extends android.support.v4.app.Fragment { @ViewById(R.id.header) View mHeaderView; + @ViewById(R.id.username) + TextView mUserName; + + @ViewById(R.id.avatar) + ImageView mAvatar; + private Disposable mConnectionStateDisposable; @@ -88,11 +101,46 @@ public class DrawerFragment extends android.support.v4.app.Fragment { syncSwitchState(); } + @Override + public void onResume() { + super.onResume(); + syncUserInfo(); + } + @AfterViews void setUpViews() { ThemeColorManager.addViewBackground(mHeaderView); } + private void syncUserInfo() { + NodeBB.getInstance().getRetrofit() + .create(UserApi.class) + .me() + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new SimpleObserver() { + @Override + public void onNext(@io.reactivex.annotations.NonNull User user) { + setUpUserInfo(user); + } + + @Override + public void onError(@io.reactivex.annotations.NonNull Throwable e) { + e.printStackTrace(); + } + }); + } + + private void setUpUserInfo(User user) { + mUserName.setText(user.getUsername()); + } + + @Click(R.id.avatar) + void loginOrShowUserInfo() { + LoginActivity_.intent(getActivity()).start(); + } + + @Click(R.id.accessibility_service) void enableOrDisableAccessibilityService() { boolean isAccessibilityServiceEnabled = isAccessibilityServiceEnabled(); @@ -173,13 +221,14 @@ public class DrawerFragment extends android.support.v4.app.Fragment { .onNeutral(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { + mConnectionItem.getSwitchCompat().setChecked(false, false); IntentUtil.browse(getActivity(), URL_SUBLIME_PLUGIN_HELP); } }) .cancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { - mConnectionItem.getSwitchCompat().toggle(false); + mConnectionItem.getSwitchCompat().setChecked(false, false); } }) .show(); diff --git a/app/src/main/java/com/stardust/widget/EWebView.java b/app/src/main/java/com/stardust/widget/EWebView.java index e5b36b46..4e062ce7 100644 --- a/app/src/main/java/com/stardust/widget/EWebView.java +++ b/app/src/main/java/com/stardust/widget/EWebView.java @@ -55,6 +55,8 @@ public class EWebView extends FrameLayout implements SwipeRefreshLayout.OnRefres settings.setBuiltInZoomControls(true); settings.setLoadWithOverviewMode(true); settings.setJavaScriptEnabled(true); + settings.setJavaScriptCanOpenWindowsAutomatically(true); + settings.setDomStorageEnabled(true); mWebView.setWebViewClient(new MyWebViewClient()); mWebView.setWebChromeClient(new MyWebChromeClient()); } diff --git a/app/src/main/java/com/stardust/widget/PrefSwitch.java b/app/src/main/java/com/stardust/widget/PrefSwitch.java index e11269b4..7aae68ec 100644 --- a/app/src/main/java/com/stardust/widget/PrefSwitch.java +++ b/app/src/main/java/com/stardust/widget/PrefSwitch.java @@ -4,7 +4,9 @@ import android.content.Context; import android.content.SharedPreferences; import android.content.res.TypedArray; import android.preference.PreferenceManager; +import android.support.annotation.IntDef; import android.util.AttributeSet; +import android.view.View; import com.stardust.scriptdroid.R; @@ -16,6 +18,7 @@ public class PrefSwitch extends SwitchCompat implements SharedPreferences.OnShar private String mPrefKey; private SharedPreferences mSharedPreferences; + private boolean mDefaultChecked; public PrefSwitch(Context context) { super(context); @@ -37,17 +40,23 @@ public class PrefSwitch extends SwitchCompat implements SharedPreferences.OnShar return; TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.PrefSwitch); mPrefKey = a.getString(R.styleable.PrefSwitch_key); - boolean defaultValue = a.getBoolean(R.styleable.PrefSwitch_defaultValue, false); + mDefaultChecked = a.getBoolean(R.styleable.PrefSwitch_defaultValue, false); if (mPrefKey != null) { mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext()); mSharedPreferences.registerOnSharedPreferenceChangeListener(this); - setChecked(mSharedPreferences.getBoolean(mPrefKey, defaultValue), false); + readInitialState(); } else { - setChecked(defaultValue, false); + setChecked(mDefaultChecked, false); } a.recycle(); } + private void readInitialState() { + if (mPrefKey == null || mSharedPreferences == null) + return; + setChecked(mSharedPreferences.getBoolean(mPrefKey, mDefaultChecked), false); + } + private void notifyPrefChanged(boolean isChecked) { if (mPrefKey == null) return; @@ -83,5 +92,12 @@ public class PrefSwitch extends SwitchCompat implements SharedPreferences.OnShar setChecked(mSharedPreferences.getBoolean(mPrefKey, isChecked()), false); } } + + @Override + protected void onWindowVisibilityChanged(int visibility) { + if (visibility == VISIBLE) { + readInitialState(); + } + } } diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml new file mode 100644 index 00000000..7ef93775 --- /dev/null +++ b/app/src/main/res/layout/activity_login.xml @@ -0,0 +1,158 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8d6e77a5..ebd246b7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -243,6 +243,12 @@ 选择文件 您的操作太快啦ヽ(#`Д´)ノ 连接中… + 用户名 + 密码 + 登录 + 忘记密码 + 用户名不能为空 + 密码不能为空 diff --git a/autojs/src/main/java/com/stardust/autojs/runtime/api/crypto/Crypto.java b/autojs/src/main/java/com/stardust/autojs/runtime/api/crypto/Crypto.java new file mode 100644 index 00000000..2fdd5589 --- /dev/null +++ b/autojs/src/main/java/com/stardust/autojs/runtime/api/crypto/Crypto.java @@ -0,0 +1,28 @@ +package com.stardust.autojs.runtime.api.crypto; + +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; + +import javax.crypto.Cipher; +import javax.crypto.KeyGenerator; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.SecretKey; + +import static javax.crypto.Cipher.ENCRYPT_MODE; + +/** + * Created by Stardust on 2017/9/20. + */ + +public class Crypto { + + public Cipher createCipher(String algorithm, String password) throws InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException { + javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance(algorithm); + KeyGenerator keyGenerator = KeyGenerator.getInstance(algorithm); + keyGenerator.init(128, new SecureRandom(password.getBytes())); + SecretKey secretKey = keyGenerator.generateKey(); + cipher.init(ENCRYPT_MODE, secretKey); + return cipher; + } +} diff --git a/inrt/build.gradle b/inrt/build.gradle index ad12bc80..775bbec6 100644 --- a/inrt/build.gradle +++ b/inrt/build.gradle @@ -16,13 +16,17 @@ android { } } + lintOptions { + disable 'MissingTranslation' + disable 'ExtraTranslation' + } buildTypes { debug { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } release { - minifyEnabled true + minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } diff --git a/inrt/src/main/AndroidManifest.xml b/inrt/src/main/AndroidManifest.xml index 8db7fb6c..8e9e2b04 100644 --- a/inrt/src/main/AndroidManifest.xml +++ b/inrt/src/main/AndroidManifest.xml @@ -17,6 +17,19 @@ + + + + + + + + \ No newline at end of file diff --git a/inrt/src/main/java/com/stardust/auojs/inrt/App.java b/inrt/src/main/java/com/stardust/auojs/inrt/App.java index 1f08a119..f61726ca 100644 --- a/inrt/src/main/java/com/stardust/auojs/inrt/App.java +++ b/inrt/src/main/java/com/stardust/auojs/inrt/App.java @@ -1,6 +1,9 @@ package com.stardust.auojs.inrt; import android.app.Application; +import android.app.Fragment; + +import com.stardust.auojs.inrt.rt.AutoJs; /** * Created by Stardust on 2017/7/1. @@ -8,9 +11,17 @@ import android.app.Application; public class App extends Application { + private static App sApp; + + public static App getApp() { + return sApp; + } + @Override public void onCreate() { super.onCreate(); + sApp = this; + AutoJs.initInstance(this); } } diff --git a/inrt/src/main/java/com/stardust/auojs/inrt/MainActivity.java b/inrt/src/main/java/com/stardust/auojs/inrt/MainActivity.java index 8ae3fe42..a023eeee 100644 --- a/inrt/src/main/java/com/stardust/auojs/inrt/MainActivity.java +++ b/inrt/src/main/java/com/stardust/auojs/inrt/MainActivity.java @@ -3,6 +3,7 @@ package com.stardust.auojs.inrt; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import com.stardust.auojs.inrt.rt.AutoJs; import com.stardust.autojs.script.StringScriptSource; import java.io.IOException; @@ -19,7 +20,7 @@ public class MainActivity extends AppCompatActivity { is.read(data); String js = new String(data); StringScriptSource source = new StringScriptSource("