Cause of the matter

I recently opened a full version of the Android framework XUpdate on Github, and it has been well received.

But as the user base grew, there were a lot of questions. One of the most common was: “Why is my version update bar not showing or updating?”

Problems arising

If I encounter this problem, I think my most direct solution is to read the source code or break points, log to locate the problem.

Why is it that everyone else can and I can’t?

Unfortunately, I find that many people’s first reaction to a problem is: what the hell is this? It doesn’t work. Then began to baidu search, or add QQ exchange group up @ me, I was very meng, specific can refer to the following picture:

At the beginning, I was also very upset about such questions:

  • First of all, there are many reasons why the version update progress bar is not displayed or not updated. It is just like you are single, but asking me how to get rid of being single is a level question. How do you want me to answer you?

  • Secondly, many of my open source frameworks have a rich wiki with a section on frequently asked questions that list common user mistakes and solutions. XUpdate, for example, has a detailed FAQ that explains why the progress bar doesn’t update and how to resolve it. But unfortunately, many people choose to turn a blind eye. Obviously, I have given you the answers, but you don’t want to copy them. There is nothing I can do.

  • At the end of the day, when the problem is not solved, most people will just walk away and turn around and find a framework that works better for them, while some people are not so kind and will talk very hard about your framework, constantly belittling your framework and acting like I owe it to them… Like this one:

My reflection

Over the years working on open source projects, I’ve been thinking about two questions:

  • Why open source?

  • What makes open source good?

Why open source

I have to admit that the original goal of my open source project was to raise my profile in the industry so that I could find a job in the future. However, as my open source project was recognized and used by more and more people, this concept gradually changed, especially when I learned that someone created a commercial grade App using my open source framework in just a few days, I was actually very happy.

Now I do open source projects, the purpose is very pure: to help people develop better, improve the efficiency and ability of development, so that people have more time to study and live, rather than endless rework in the company.

However, according to my observation, many people use open source projects only to solve their problems, which is called “taking advantage”. They do not study and learn the design structure or implementation principle of the project, which is completely contrary to my original intention of doing open source projects.

I always stress that knowing how to use a framework doesn’t mean you know how to use a framework. Can only use the framework and not to learn the framework design ideas and implementation principles, then you are used to be skilled, the framework is still someone else, you are still only a junior development engineer.

What’s more, if you use a framework without knowing how it works, what will you do if the development fails? Are you going to continue to change the framework?

So, I still encourage my framework users to solve their own problems by looking at documentation, source code, and clever design ideas in the framework, rather than solving problems for the sake of solving them.

What makes open source good

When I started doing open source, I made a common mistake of open source: cognitive error!

I naively believed that the users of my open source project were professionals of similar level to myself, and they knew a lot of jargon or basic knowledge by default, which led to a lot of bugs or unclear descriptions in the early stage of the open source project.

Take my XUpdate project as an example. In the past three years, I have solved 100+ issues one by one. Can you believe that I can handle so many problems with a simple Android version update?

One day, a user in the QQ communication group came up directly @ me: there is a download progress, but why does the progress bar not show? And sent their own download function implementation logic code as shown below:

At the beginning of this string of code, I found something wrong: this guy does not speak wude ah, how can the child thread directly callback progress update, this is afraid not to write Android bar…

So, I directly in the group back a “you are really talented, in the child thread callback”, and then silently open XUpdate source code, to all callbacks involving UI updates have added a thread judgment, to ensure that the main thread processing UI.

But as I was writing, I began to wonder, if the UI is really handled in child threads, why doesn’t the application crash?

Sure enough, I was right. The guy took my advice: he moved the callback to the main thread and still couldn’t display the progress bar.

And when I see this, my gut tells me it probably doesn’t have anything to do with the progress callback here. So I re-opened the progress bar updated source code, looked at it carefully, and then compared the code he sent before, I suddenly realized:

Here handleStart corresponds to onStart for downloading the callback, and handleProgress corresponds to onProgress for downloading the callback. The complete definition of the download callback interface is as follows:

/** * Download callback */
interface DownloadCallback {
    /** ** before downloading */
    void onStart(a);

    /** * Update progress **@paramProgress 0.00-0.50-1.00 *@paramTotal Total file size in bytes */
    void onProgress(float progress, long total);

    /** * result callback **@paramFile Downloaded file */
    void onSuccess(File file);

    /** * error callback **@paramThrowable error */
    void onError(Throwable throwable);
}
Copy the code

Obviously, this man only implements onProgress callback interface, but not realize the onStart callback interface, this leads to handleStart method mNumberProgressBar inside. The setVisibility (the VISIBLE). The progress bar was never executed, and there is no way to display the progress bar in the handleProgress method, so of course the progress bar is never displayed…

When I saw this, ALL I wanted to say was, “I was careless. I didn’t blink!” . If this guy hadn’t posted his sexy code, I never would have thought it would happen!

Joking aside, there is a loophole in the logic here, so it needs to be compatible. So I added another layer of judgment where I updated the progress bar: if the progress bar is not currently displayed, display it first and then update the progress. The code changes are as follows:

The lesson I learned the hard way is that you can never guess who is on the other end of the computer and how to use your open source projects.

To this end, I specifically made the following improvements for the XUpdate open source project:

  • Change thinking, stand in the small white point of view, recomb the existing use of the document, make the document more simple and easy to understand.
  • Wrote a simplified library of XUpdate XUpdateAPI:github.com/xuexiangjys… To make XUpdate easier to use.
  • Have made several XUpdate related teaching video: space.bilibili.com/483850585/c…

conclusion

With that said, let’s briefly summarize my reflections:

  • 1. When using open source projects, we should pay attention to studying and studying their design ideas and implementation principles, and refuse to adopt them.
  • 2. The purpose of doing open source projects should be to learn and communicate and help more people grow, rather than for their own selfish interests.
  • 3. A good open source project should analyze and solve problems from the point of view of users, and projects divorced from users will eventually be abandoned.

My name is Xuexiangjys, a technical master who loves learning and programming, and is committed to Android architecture research and experience sharing of open source projects. If you want to get more information, please search my wechat official account: [My Android open Source Journey]