Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Ptt Project #1

Open
3 of 7 tasks
ininmm opened this issue Dec 8, 2020 · 20 comments
Open
3 of 7 tasks

Refactor Ptt Project #1

ininmm opened this issue Dec 8, 2020 · 20 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@ininmm
Copy link
Collaborator

ininmm commented Dec 8, 2020

In GitLab by @in_in_mm on Oct 28, 2020, 22:10

前言

規劃專案重構的思路。

因為當前迫切的需求是在 github open source ,所以第一階段目標是能讓其他人能夠協作為優先。

以下是大概的重構思路,有 highlight 的是必須要做的,其他則是有空時可以慢慢改。

Detail

  • 整理專案:統一專案風格、刪除個人訊息

    • 調整專案配置:刪除多餘的檔案,整理 git 、 gradle 等 config 的設定
    • 格式化:reformat 程式碼並加入一些基本的 lint ,規則以 google 的 coding style 為準
    • 變更程式語言:從 Java 換成 Kotlin
    • CI:檢查程式碼是否符合規範
  • 抽象化:之後專案會以 MVVM 為目標,但須先將專案的 controller 及資料層的公開方法介面化

    • 定義 scope:專案大致會先分成 ViewViewModelRepository
    • ISP:將大的 interface 切割成單一職責的小模塊
    • 控制反轉:把 class 依賴的 interface 改成建構子注入
    • 測試:加入 unit test 或是整合測試
    • DI:後續根據切割後的子組件決定是否有必要加入 DI 的概念
  • 其他:這些是可做可不做,或是需要邊做邊想的事情

    • 非同步調用:要想一下這個專案的實作方式,主流大概有 Callback、RxJava、Coroutines、(LiveData)Select a concurrency design pattern to simplify code that executes asynchronously #13

      可以調整成:
      UI <-> ViewModel 使用 LiveData
      ViewModel <-> 使用 Callback

    • Thread Handle:整理執行緒的調用方式,最好可以用 thread pool 之類的方式集中處理
    • Error Handle:錯誤處理的機制
    • API:okhttp、retrofit?
    • database:有需要改成 Room 之類的嗎? 因為需要存的 local 資料不多,可以考慮用 android keystore
    • 專案模組化:讓後續開發時可以更針對功能去開發,同時加強專案編譯效能
    • 圖片框架考慮替換成 Glide

Discussion

重構會分成幾個階段,第一階段會先 整理專案

第二階段初步抽象化後,改為由下往上開發,從最底層的資料層重構,先建立一個 MVVM 結構。

  • 整理專案 Config
  • reformat 並加入 lint check (git hook)
  • 根據 UI 提出的功能分割出 ViewModel & Open Source to GitHub
  • 各層級抽象化
  • 資料層根據資料類型分成 local 資料或是網路資料
  • 可以加入 Repository 的概念,整合資料層
  • (後續重構的想法可以在這裡提出)

Appendix

以下是之前 slack 整理的專案可能會用到技術選型或是套件 (感謝 @chrisynchen 整理)

Networking:

  • retrofit2 + OKHttp3
  • Volley

ImageLoader:

  • Glide
  • Picasso
  • coil

Architecture:

  • MVP
  • MVVM

Async work:

  • rxjava2
  • coroutines

DI:

  • dagger2
  • koin
  • Hilt

CI/CD:

  • travis
  • circle ci
  • GitHub Action

Test libs:

  • Power mock
  • Mockito
  • MockK
  • Google trust
  • MockWebServer
@ininmm ininmm added enhancement New feature or request good first issue Good for newcomers labels Dec 8, 2020
@ininmm
Copy link
Collaborator Author

ininmm commented Dec 8, 2020

In GitLab by @in_in_mm on Oct 28, 2020, 22:11

assigned to @kenhuang1120 and unassigned @in_in_mm

@ininmm
Copy link
Collaborator Author

ininmm commented Dec 8, 2020

In GitLab by @in_in_mm on Oct 28, 2020, 22:11

assigned to @in_in_mm and unassigned @kenhuang1120

@ininmm
Copy link
Collaborator Author

ininmm commented Dec 8, 2020

In GitLab by @in_in_mm on Oct 29, 2020, 00:41

@kenhuang1120

@ininmm
Copy link
Collaborator Author

ininmm commented Dec 8, 2020

In GitLab by @in_in_mm on Oct 29, 2020, 21:58

changed the description

@ininmm
Copy link
Collaborator Author

ininmm commented Dec 8, 2020

In GitLab by @in_in_mm on Oct 31, 2020, 13:29

marked this issue as related to #2

@ininmm
Copy link
Collaborator Author

ininmm commented Dec 8, 2020

In GitLab by @in_in_mm on Oct 31, 2020, 22:17

mentioned in merge request !2

@ininmm
Copy link
Collaborator Author

ininmm commented Dec 8, 2020

In GitLab by @in_in_mm on Oct 31, 2020, 23:30

marked the task 整理專案 Config as completed

@ininmm
Copy link
Collaborator Author

ininmm commented Dec 8, 2020

In GitLab by @in_in_mm on Nov 3, 2020, 01:03

mentioned in merge request !5

@ininmm
Copy link
Collaborator Author

ininmm commented Dec 8, 2020

In GitLab by @in_in_mm on Nov 3, 2020, 11:16

marked the task reformat 並加入 lint check (git hook) as completed

@ininmm
Copy link
Collaborator Author

ininmm commented Dec 8, 2020

In GitLab by @in_in_mm on Nov 5, 2020, 00:40

marked this issue as related to #6

@ininmm
Copy link
Collaborator Author

ininmm commented Dec 8, 2020

In GitLab by @TakumaLee on Nov 5, 2020, 13:35

可以一同建立 Unit Test,搭配測試 ViewModel 確保邏輯正確

@ininmm
Copy link
Collaborator Author

ininmm commented Dec 8, 2020

In GitLab by @in_in_mm on Nov 5, 2020, 14:11

made the issue visible to everyone

@ininmm
Copy link
Collaborator Author

ininmm commented Dec 8, 2020

In GitLab by @in_in_mm on Nov 6, 2020, 00:24

可能要先有個簡單的架構出來,才比較好寫測試?

我有想過要不要改的時候至少寫個最簡單的測試出來也好,主要是不太可能有辦法一步到位。

我之前寫 Unit 的經驗是如果沒有先把 class 間的依賴關係切的很清楚的話,要嘛實作起來很痛苦,不然就是寫出來的測試粒度太粗反而沒有實質上的意義

倒是可以考慮之後整理程式碼的時候先寫測試再完成程式

@ininmm
Copy link
Collaborator Author

ininmm commented Dec 8, 2020

In GitLab by @Aidan79225 on Nov 10, 2020, 23:22

marked this issue as related to #12

@ininmm
Copy link
Collaborator Author

ininmm commented Dec 8, 2020

In GitLab by @Aidan79225 on Nov 19, 2020, 22:35

marked this issue as related to #18

@ininmm
Copy link
Collaborator Author

ininmm commented Dec 8, 2020

In GitLab by @Aidan79225 on Nov 19, 2020, 22:37

marked this issue as related to #19

@ininmm
Copy link
Collaborator Author

ininmm commented Dec 8, 2020

In GitLab by @in_in_mm on Nov 25, 2020, 13:32

changed title from Refactor {-code base-} to Refactor {+Ptt Project+}

@ininmm
Copy link
Collaborator Author

ininmm commented Dec 8, 2020

In GitLab by @in_in_mm on Nov 25, 2020, 13:34

changed the description

@ininmm
Copy link
Collaborator Author

ininmm commented Dec 8, 2020

In GitLab by @in_in_mm on Nov 25, 2020, 14:20

changed the description

@ininmm
Copy link
Collaborator Author

ininmm commented Dec 8, 2020

In GitLab by @in_in_mm on Nov 26, 2020, 17:09

changed the description

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant