Skip to content

Commit

Permalink
feat: 对接新的测量协议
Browse files Browse the repository at this point in the history
  • Loading branch information
LitterSun authored and 小肥阳 committed Aug 25, 2020
1 parent 3d839aa commit 4973579
Show file tree
Hide file tree
Showing 60 changed files with 1,422 additions and 1,061 deletions.
1 change: 1 addition & 0 deletions demos/demo-autotrack/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencies {
implementation 'android.arch.lifecycle:livedata:1.1.1'
implementation 'android.arch.lifecycle:viewmodel:1.1.1'
api 'com.tencent.tbs.tbssdk:sdk:43903'
implementation 'com.android.support:support-annotations:28.0.0'

compileOnly libraries.androidx.appcompat
compileOnly libraries.androidx.recyclerview
Expand Down
5 changes: 4 additions & 1 deletion demos/demo-autotrack/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
<uses-permission android:name="android.permission.VIBRATE" />

<application>
<activity android:name=".activity.ExpandableListSubActivity"></activity>
<activity
android:name=".activity.ui.login.LoginActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
<activity android:name=".activity.ExpandableListSubActivity" />
<activity android:name=".activity.ExpandableListViewActivity" />
<activity android:name=".activity.ClickTestActivity" />
<activity android:name=".activity.RecyclerViewImpActivity" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.gio.test.three.autotrack.activity.TabFragmentActivity;
import com.gio.test.three.autotrack.activity.WebViewActivity;
import com.gio.test.three.autotrack.activity.X5WebViewActivity;
import com.gio.test.three.autotrack.activity.ui.login.LoginActivity;
import com.growingio.android.sdk.autotrack.GrowingAutotracker;
import com.growingio.android.sdk.autotrack.IgnorePolicy;
import com.growingio.android.sdk.autotrack.view.ViewAttributeUtil;
Expand All @@ -64,6 +65,7 @@ public class AutotrackEntryActivity extends Activity {
private static final String GO_TO_CLICK_TEST_ACTIVITY = "Go To ClickTestActivity";
private static final String GO_TO_EXPANDABLE_LIST_VIEW_ACTIVITY = "Go To ExpandableListViewActivity";
private static final String GO_TO_EXPANDABLE_LIST_SUB_ACTIVITY = "Go To ExpandableListSubActivity";
private static final String GO_TO_LOGIN_ACTIVITY = "Go To LoginActivity";


private static final String[] ITEMS = {
Expand All @@ -80,6 +82,7 @@ public class AutotrackEntryActivity extends Activity {
GO_TO_CLICK_TEST_ACTIVITY,
GO_TO_EXPANDABLE_LIST_VIEW_ACTIVITY,
GO_TO_EXPANDABLE_LIST_SUB_ACTIVITY,
GO_TO_LOGIN_ACTIVITY,
};

@Override
Expand Down Expand Up @@ -179,6 +182,9 @@ private void handleItemClick(String itemString) {
case GO_TO_EXPANDABLE_LIST_SUB_ACTIVITY:
startActivity(new Intent(this, ExpandableListSubActivity.class));
break;
case GO_TO_LOGIN_ACTIVITY:
startActivity(new Intent(this, LoginActivity.class));
break;
default:
throw new IllegalStateException("Unexpected value: " + itemString);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2020 Beijing Yishu Technology Co., Ltd.
*
* 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 com.gio.test.three.autotrack.activity.data;

import com.gio.test.three.autotrack.activity.data.model.LoggedInUser;

import java.io.IOException;

/**
* Class that handles authentication w/ login credentials and retrieves user information.
*/
public class LoginDataSource {

public Result<LoggedInUser> login(String username, String password) {

try {
// TODO: handle loggedInUser authentication
LoggedInUser fakeUser =
new LoggedInUser(
java.util.UUID.randomUUID().toString(),
"Jane Doe");
return new Result.Success<>(fakeUser);
} catch (Exception e) {
return new Result.Error(new IOException("Error logging in", e));
}
}

public void logout() {
// TODO: revoke authentication
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (C) 2020 Beijing Yishu Technology Co., Ltd.
*
* 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 com.gio.test.three.autotrack.activity.data;

import com.gio.test.three.autotrack.activity.data.model.LoggedInUser;

/**
* Class that requests authentication and user information from the remote data source and
* maintains an in-memory cache of login status and user credentials information.
*/
public class LoginRepository {

private static volatile LoginRepository sInstance;

private LoginDataSource mDataSource;

// If user credentials will be cached in local storage, it is recommended it be encrypted
// @see https://developer.android.com/training/articles/keystore
private LoggedInUser mUser = null;

// private constructor : singleton access
private LoginRepository(LoginDataSource dataSource) {
this.mDataSource = dataSource;
}

public static LoginRepository getInstance(LoginDataSource dataSource) {
if (sInstance == null) {
sInstance = new LoginRepository(dataSource);
}
return sInstance;
}

public boolean isLoggedIn() {
return mUser != null;
}

public void logout() {
mUser = null;
mDataSource.logout();
}

private void setLoggedInUser(LoggedInUser user) {
this.mUser = user;
// If user credentials will be cached in local storage, it is recommended it be encrypted
// @see https://developer.android.com/training/articles/keystore
}

public Result<LoggedInUser> login(String username, String password) {
// handle login
Result<LoggedInUser> result = mDataSource.login(username, password);
if (result instanceof Result.Success) {
setLoggedInUser(((Result.Success<LoggedInUser>) result).getData());
}
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (C) 2020 Beijing Yishu Technology Co., Ltd.
*
* 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 com.gio.test.three.autotrack.activity.data;

/**
* A generic class that holds a result success w/ data or an error exception.
*/
public class Result<T> {
// hide the private constructor to limit subclass types (Success, Error)
private Result() {
}

@Override
public String toString() {
if (this instanceof Result.Success) {
Result.Success success = (Result.Success) this;
return "Success[data=" + success.getData().toString() + "]";
} else if (this instanceof Result.Error) {
Result.Error error = (Result.Error) this;
return "Error[exception=" + error.getError().toString() + "]";
}
return "";
}

// Success sub-class
public final static class Success<T> extends Result {
private T mData;

public Success(T data) {
this.mData = data;
}

public T getData() {
return this.mData;
}
}

// Error sub-class
public final static class Error extends Result {
private Exception mError;

public Error(Exception error) {
this.mError = error;
}

public Exception getError() {
return this.mError;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2020 Beijing Yishu Technology Co., Ltd.
*
* 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 com.gio.test.three.autotrack.activity.data.model;

/**
* Data class that captures user information for logged in users retrieved from LoginRepository
*/
public class LoggedInUser {

private String mUserId;
private String mDisplayName;

public LoggedInUser(String userId, String displayName) {
this.mUserId = userId;
this.mDisplayName = displayName;
}

public String getUserId() {
return mUserId;
}

public String getDisplayName() {
return mDisplayName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2020 Beijing Yishu Technology Co., Ltd.
*
* 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 com.gio.test.three.autotrack.activity.ui.login;

/**
* Class exposing authenticated user details to the UI.
*/
class LoggedInUserView {
private String mDisplayName;
//... other data fields that may be accessible to the UI

LoggedInUserView(String displayName) {
this.mDisplayName = displayName;
}

String getDisplayName() {
return mDisplayName;
}
}
Loading

0 comments on commit 4973579

Please sign in to comment.